I have a json where one parent array, and every object of parent array there is another child array pozzles
.
So what I want to do is, there is one key-value( title
) of parent item I want to add in every item of child array.
Check this json screen shot to understand clear.
Is there any direct method available in js
to do this?
Considering this is your data
const data = [{ id: 1, title: "some", pozzles: [{ id: "1A" }, { id: "1B" }] }, { id: 2, title: "some2", pozzles: [{ id: "2A" }, { id: "2B" }] }];
data.forEach(d => {
d.pozzles.forEach(p => { p.title = d.title })
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.