Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:38:29+00:00 2026-06-11T16:38:29+00:00

I want need to translate a notation (e.g. ‘main:message:new’) to the referred object property

  • 0

I want need to translate a notation (e.g. ‘main:message:new’) to the referred object property (resource[main][message][new]).

var notation = 'main:message:new';

var ressource = {
    message: { new: 'something' }
};

var splitKeys = function(keys, object) {
    var keys, pointer;
    pointer = object;
    keys = keys.split(':');
    for (i = 0; i < keys.length; i++) {
        // here is the error
        if (pointer[keys[i]] === undefined) break;
        pointer = pointer[keys[i]];
    }
    return pointer;
};

console.log(splitKeys(notation, ressource));

As you see I got problems with the error handling. If there is a ressource notation which doesn’t match a concrete ressource I want to return nothing. Unfortunately I always get an error thrown ‘cannot read property undefined of undefined’…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:38:30+00:00Added an answer on June 11, 2026 at 4:38 pm

    The first property name, called main, is not present in your resource object, thus your method will always return the entire object instead of the property value you are aiming at, which is { new: 'something' }:

    var splitKeys = function(keys, object) {
        var pointer = object;
        var parent = pointer;
        keys = keys.split(':').slice(1); // exclude `main`
        for (var i = 0; i < keys.length; i++) {
            if (pointer[keys[i]] === undefined) break;
            parent = pointer;
            pointer = pointer[keys[i]];
        }
        return parent;
    };
    

    This will return the new object, i.e., { new: 'something' }. If you want to return the property value instead, return pointer instead of parent.

    DEMO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume a user enter address of some resource and we need to translate
In my iPhone OS application I want (need) to watch for changes in the
Potentially embarrassing question, but there is obviously something I'm missing that I want/need to
I want to (need to) start a sub-process from a perl script that checks
I want (or need) to do something along the lines of char **my_array =
I need a regex for date format in python I want March 29 but
I want to implement a REST API and need a body on my GET
I need a little help getting this script doing what I want it to.
I need a jquery slideshow with div popup i want to show my image
I need to build a DSL Solution using MsBuild and want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.