How can I change a specific object in a state for example, I have data like this
const colors= [
{
id: 1,
name: "red",
},
{
id: 1,
name: "green",
},
{
id: 2,
name: "blue",
},
];
const storage = [{
id:2,
name:"64 GB"
},
{
id:2,
name:"128 GB"
]
The state value should be like this [{id:1, name:'red"}, {id:2,name:"128GB"}]
Is there any way to update the state based on the id only? For example: I need to loop on the data and if the state.id === id it will update that specific object.
So in our example, I need to update the state to be [{id:1, name:'green"}, {id:2,name:"128GB"}] if the state.id === 1
Thanks in advance
Array.map