I want to update the value of my array of an object matching "key". The find index is working but it's actually pushing the value instead of replacing it?
this.state.data = thedata Array [
Object {
"key": "-Lu2u6ib92Ay8Pw1O-3m",
"question": "1",
},
Object {
"key": "-Lu2u8kZRs2E4X4TgxZd",
"question": "4",
},
Object {
"key": "-Lu2u7z4--ImiPSkWa1B",
"question": "3",
},
this.state.data[this.state.data.findIndex(el => el.key === '-Lu2u7z4--ImiPSkWa1B')] = 'totototot';
Actual output pushes the value to the index but not replacing it:
this.state.data = thedata Array [
totototot,
Object {
"key": "-Lu2u6ib92Ay8Pw1O-3m",
"question": "1",
},
Object {
"key": "-Lu2u8kZRs2E4X4TgxZd",
"question": "4",
},
Object {
"key": "-Lu2u7z4--ImiPSkWa1B",
"question": "3",
},
Expected output:
this.state.data = thedata Array [
Object {
"key": "-Lu2u6ib92Ay8Pw1O-3m",
"question": "1",
},
Object {
"key": "-Lu2u8kZRs2E4X4TgxZd",
"question": "4",
},
totototot,