no se pueden cambiar los elementos según la identificación y el resultado esperado debe estar en formato de salida
const items = [ { id: 1, value: "first" }, { id: 2, value: "second" }, { id: 3, value: "third" } ]; const expectedOutput = [ { id: 1, value: "first" }, { id: 2, value: "newvalue" }, { id: 3, value: "third" } ] function getData(value, id) { return items.map((_each)=> { if(_each.id === id) { //need to update items with id=2 } }) } console.log(getData("newvalue", 2)) const items = [ { id: 1, value: "first" }, { id: 2, value: "second" }, { id: 3, value: "third" } ]; const expectedOutput = [ { id: 1, value: "first" }, { id: 2, value: "newvalue" }, { id: 3, value: "third" } ] function getData(value, id) { return items.map((each)=> { if(each.id === id) { //need to update items with id=2 return {...each, value} }else{ return each } }) } console.log(getData("newvalue", 2))