45
rated 0 times
[
52]
[
7]
/ answers: 1 / hits: 32769
/ 5 Years ago, thu, june 27, 2019, 12:00:00
I have an object like this:
{
responses: {
firstKey: {
items: {
name: test name one
}
},
anotherKey: {
items: {
name: test name two
}
},
oneMoreKey: {
items: {
name: John
}
}
}
}
I need to find all 'name' keys and replace its value only if it starts with 'test name' then return new JSON object:
{
responses: {
firstKey: {
items: {
name: N/A
}
},
anotherKey: {
items: {
name: N/A
}
},
oneMoreKey: {
items: {
name: John
}
}
}
}
The problem is that the keys are not consistent through the objects, i.e. 'firstKey', 'secondKey'... I tried ForEach but it seems to be too cumbersome... So I need either lodash or vanila JavaScript to replace the values.
More From » node.js