Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

374
Views
how to get all the values inside JSON with a common name?

I need to get an array of all the name values from a JSON structure.

My JSON looks like this:

{
  "profile": {
    "G5j7": {
      "name": "siddharth",
      "age": "17"
    },
    "Loj9": {
      "name": "ram",
      "age": "20"
    },
    "Huy8": {
      "name": "maix"
    }
  }
}

I can get a specific name value by:

var singleName = profile.G5j7.name;

But how do I get an array of all the name values if don't know all the IDs inside profile? I need to store in a variable.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

const arrayName = Object.values(profile).map((item) => item.name);
about 4 years ago · Juan Pablo Isaza Report

0

You can use Object.keys to get all properties keys in an Object, with that you can get access to all profile object keys with that you can retrieve name for each key like bellow

let data = {
    "profile": {
        "G5j7": {
            "name": "siddharth",
            "age": "17"
        },
        "Loj9": {
            "name": "ram",
            "age": "20"
        },
        "Huy8": {
            "name": "maix"
        }
  }
};

let profiles_keys = Object.keys(data.profile);

let results = profiles_keys.reduce((accumulator, current)=> {
    return accumulator.concat(data.profile[current].name)
}, []);

console.log(results);

about 4 years ago · Juan Pablo Isaza Report

0

Object.values(yourObj.profile).map(v => v.name)

Object.values() returns an array of the values on every (own) prop of your object. So you can forget about the property names and iterate on its values

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!