I have this data structure
[
{photos: [{name:'abc'}]},
{photos: [{name:'xyz'}]},
]
How can I add name property as photo's sibling like this
[
{photos: [{name:'abc'}], name:'abc'}
{photos: [{name:'xyz'}], name: 'xyz'},
]
I have this data structure
[
{photos: [{name:'abc'}]},
{photos: [{name:'xyz'}]},
]
How can I add name property as photo's sibling like this
[
{photos: [{name:'abc'}], name:'abc'}
{photos: [{name:'xyz'}], name: 'xyz'},
]
Something like that:
var src = [
{photos: [{name:'abc'}]},
{photos: [{name:'xyz'}]},
]
var dest = src.map(function (item) {
return { photos: item.photos, name : item.photos[0].name}
})
Something like this?
x = [
{photos: [{name:'abc'}]},
{photos: [{name:'xyz'}]},
]
x[0].name = "abc"
console.log(x)
OP:- [
{photos: [{name:'abc'}], name:'abc'}
{photos: [{name:'xyz'}]},
]
Since this is an example I am just posting a way to add the name attribute. What's happening here is that since x is an array of json objects, it is simple to add attributes to the json object via x[0]