Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change specific object in array javascript

//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));

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

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

PREVIOUS NEXT
Code Example
Javascript :: inline style vue 
Javascript :: Codewars Square(n) Sum 
Javascript :: how to hide javascript element by class 
Javascript :: remove null values from json object in javascript 
Javascript :: jquery get top position of element on scroll 
Javascript :: JavaScript changing the color of an html element 
Javascript :: regex check is valid ip 
Javascript :: set cookie javascript 
Javascript :: js clear local storage 
Javascript :: sum an array in javascript 
Javascript :: node file change event listener 
Javascript :: mongodb unshift array 
Javascript :: laravel ajax form submit 
Javascript :: scroll to bottom javascript 
Javascript :: iterate over array backwards javascript 
Javascript :: react useref file input 
Javascript :: jQuery delete all spans in a div 
Javascript :: select all checkboxes jquery 
Javascript :: discord.js role regex 
Javascript :: expo build 
Javascript :: how to get current day in javascript 
Javascript :: getelementbytagname js 
Javascript :: jquery confirm delete massege 
Javascript :: node js utf8 encode 
Javascript :: detect mobile device 
Javascript :: usestate hook for checkbox check and uncheck 
Javascript :: js ask before close 
Javascript :: js simulate keyboard input 
Javascript :: js get difference in days 
Javascript :: javascript change color of button 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =