I have a JSON
const myJSON = [
{
name: 'compass',
LocX: 35,
LocY: 312
},
{
name: 'another',
LocX: 52,
LocY: 32
}
]
From the UI, if a user wants to add number 5 to one of the two properties, how should I handle this?
I am already doing
myJSON.map(x => x[userSelectedProperty] + 5)
// when user selected property is 'LocX', [40, 57]
but I want the full array with just the value updated.
[
{
name: 'compass',
LocX: 40,
LocY: 312
},
{
name: 'another',
LocX: 57,
LocY: 32
}
]
How do I do this?