Answers for "update an item in array of object"

10

update an item in array of object

//Initailize array of objects.
let myArray = [
  {id: 0, name: "Jhon"},
  {id: 1, name: "Sara"},
  {id: 2, name: "Domnic"},
  {id: 3, name: "Bravo"}
],
    
//Find index of specific object using findIndex method.    
objIndex = myArray.findIndex((obj => obj.id == 1));

//Log object to Console.
console.log("Before update: ", myArray[objIndex])

//Update object's name property.
myArray[objIndex].name = "Laila"

//Log object to console again.
console.log("After update: ", myArray[objIndex])
Posted by: Guest on May-11-2020
0

updating objects from array

receivedRates.indices.forEach{ receivedRates[$0] *= Double(inputTextField.text!)! }
Posted by: Guest on July-21-2021

Code answers related to "update an item in array of object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language