this is my data structure:
[
0:
key1: value,
key2: value,
array:
0:
thisId: xxxxx,
thisValue: value,
1:
notThisId: someId,
notThisValue: value,
key3: value
1:
key1: value
key2: value
array:
0:
anotherId: id
anotherValue: value
key3: value
]
Hello, I have a query with is returning:
thisIdRef: xxxxx,
thisNewValue: newValue
Is it possible to update the nested ‘thisValue’ to ‘thisNewValue’ where ‘thisIdRef’ is equal to ‘thisId’, or ‘xxxxx’?
I have done something similar below using findIndex and splice, but this is for a non-nested key/value pair and I can’t work out how to find a nested id, or indeed if it’s possible.
let newArray = oldArray;
const index = newArray.findIndex(post => post._id === editedPostId)
newArray.splice(index, 1, {
...newArray[index],
post: editedContent
})
Any help very much appreciated.