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 8823585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:23:35+00:00 2026-06-14T06:23:35+00:00

I want to make a simple app that receives a json object, and a

  • 0

I want to make a simple app that receives a json object, and a path. The result is the value of that path, for example:

node {"asd":{"qwe":"123", "ert":"465"}} asd.qwe

should return me: 123

I’m using this:

var result = JSON.parse(jsonToBeParsed);
console.log(result["asd"]["qwe"]);

But I want to be able of getting the values dinamically with a string.
Is there a way to do something like this? :

var result = JSON.parse(jsonToBeParsed);
var path = "asd.qwe" //or whatever
console.log(result[path]);
  • 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-14T06:23:37+00:00Added an answer on June 14, 2026 at 6:23 am
    var current = result,
        path = 'asd.qwe';
    
    path.split('.').forEach(function(token) {
      current = current && current[token];
    });
    
    console.log(current);// Would be undefined if path didn't match anything in "result" var
    

    EDIT

    The purpose of current && ... is so that if current is undefined (due to an invalid path) the script won’t try to evaluate undefined["something"] which would throw an error. However, I’ve just realized the if current happens to be falsy (i.e. false or zero or an empty string) this would fail to look up the property in token. So probably the check should be current != null.

    ANOTHER EDIT

    Here’s a much better, idiomatic way to do it in one line, using the Array.reduce() method:

    path.split('.').reduce(
      function(memo, token) {
        return memo != null && memo[token];
      },
      resultJson
    );
    

    This is also better because it doesn’t require ANY vars

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

Sidebar

Related Questions

I have a simple address book app that I want to make searchable. The
I want to make a simple Sinatra app that when I navigate to /proxy/:someurl
Background In Java, I want to make a simple, quick console app that provides
I want to make a simple app that shows a list of contacts (name,
I'm familiar with core data but want to make a simple app that calculates
I want to make a simple Android App that will download another app, install
I want to make a simple GAE app in Go that will let users
I want to make a simple app, where a UIWebView with custom content will
I am a newbie to iPhone app development. I want to make a simple
Basically I want to make simple toggle program (that will be mapped to some

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.