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

158
Views
getting nested value by using node js / javascript

let data =
 [
    {
        "testingNewValue": {
            "en-US": "hello"
        }
    },
    {
        "testingNewValue": {
            "hi-IN": "hello "
        }
    },
    {
        "testingNewValue": {
            "us": "dummy"
        }
    },
    {
        "testingNewValue": {
            "xp-op-as": "value for testing"
        },
        "locationField": {
            "en-US": {
                "lat": 19.28563,
                "lon": 72.8691
            }
        }
    }
]

const value = Object.fromEntries(Object.entries(data).map(el=>(el[1]=Object.values(el[1])[0], el)))
    console.log(value);

I am trying to get value from the data json by using the object.fromEntries n object.entries but its not working as my expectation as I am expecting the value as

Expectation

{
  {
    testingNewValue:"hello"
  },
  {
    testingNewValue:"hello"
  },
  {
    testingNewValue:"dummy"
  },
  {
    testingNewValue:"value for testing",
    locationField:{
      lat: 19.28563,
      lon: 72.8691
    }
  }
}

but I am getting "0","1","2" as you can see in code snippet as I want to remove all "en-US","hi-In" n all from data

How can I get my expectation

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Provided that you're actually after an array (as your current expected result isn't a valid structure), you should be taking the entires of each inner objects and then taking building your new object with fromEntries() after mapping each entry, rather then taking the entires of your entire data array which is causing the indexes to appear in your current result. The below code assumes you have one value within each inner object, and that each value is an object:

const data = [ { "testingNewValue": { "en-US": "hello" } }, { "testingNewValue": { "hi-IN": "hello " } }, { "testingNewValue": { "us": "dummy" } }, { "testingNewValue": { "xp-op-as": "value for testing" }, "locationField": { "en-US": { "lat": 19.28563, "lon": 72.8691 } } } ];

const value = data.map(el=>
  Object.fromEntries(Object.entries(el).map(([k, v]) => [k, Object.values(v)[0]]))
);
console.log(value);

over 4 years ago · Santiago Trujillo 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!