JSFiddle - React, Tailwind, and code Playground

by helgatheviking

JavaScript

var myArray = [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Peter"},
    {"id": 3, "name": "Harry"}
];

// Get the Array item which matchs the id "2"
var result = myArray.findIndex(item => item.id === 1);

if ( result >= 0 ) {
	myArray[result].name = 'Kathy';
}


console.log(myArray);  // Prints: Peter