Answers for "how to update the object value of any array key based on value"

10

how to update the object value of any array key based on value

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

how to update the object value of any array key based on value

const newProjects = projects.map(p =>
  p.value === 'jquery-ui'
    ? { ...p, desc: 'new description' }
    : p
);
Posted by: Guest on July-25-2021
0

how to update the object value of any array key based on value

var projects = [
    {
        value: "jquery",
        label: "jQuery",
        desc: "the write less, do more, JavaScript library",
        icon: "jquery_32x32.png"
    },
    {
        value: "jquery-ui",
        label: "jQuery UI",
        desc: "the official user interface library for jQuery",
        icon: "jqueryui_32x32.png"
    },
    {
        value: "sizzlejs",
        label: "Sizzle JS",
        desc: "a pure-JavaScript CSS selector engine",
        icon: "sizzlejs_32x32.png"
    }
];
Posted by: Guest on July-25-2021
0

how to update the object value of any array key based on value

var projects = {
   jqueryUi : {
      value:  'lol1',
      desc:   'lol2'
   }
};

projects.jqueryUi.desc = 'new string';
Posted by: Guest on July-25-2021
0

how to update the object value of any array key based on value

var projects = [ ... ];
changeDesc ( 'jquery-ui', 'new description' );
Posted by: Guest on July-25-2021

Code answers related to "how to update the object value of any array key based on value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language