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

151
Views
How can I get data from JSON array using the array's elements?
{
"Centers": {
    "Athens": [
        {
            "name":"name1",
            "lat":"",
            "lon":"",
            "address":"address1",
            "tel":"",
            "email":"",
            "link":""
        },
        {
            "name":"name2",
            "lat":"",
            "lon":"",
            "address":"address2",
            "tel":"",
            "email":"",
            "link":""
        }       
    ]
}
}

I have this JSON file and I want to get the address of an element I specify using its name. Something like this:

alert( stores.Centers.Athens["name"=="name1"].address );

Is there any way I can achieve this, or should I remake my JSON file?

Edit:

.find(x => x.name === 'name1') doesn't work. It returns 'undefined'. findIndex() also returns '-1'. I suspect it's because it is a JSON file and not an object list, meaning the property keys are doublequoted.

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

0

You can easiy achieve the result using find and optional chaining

stores.Centers.Athens.find((o) => o.name === "name1")?.address

const stores = {
  Centers: {
    Athens: [
      {
        name: "name1",
        lat: "",
        lon: "",
        address: "address1",
        tel: "",
        email: "",
        link: "",
      },
      {
        name: "name2",
        lat: "",
        lon: "",
        address: "address2",
        tel: "",
        email: "",
        link: "",
      },
    ],
  },
};
const address = stores.Centers.Athens.find((o) => o.name === "name1")?.address;
console.log(address);

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!