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
{}must have a key for each value. Did you mean to use an array[]for the outer brackets?en-Us hi-Inand get the value as expected