Answers for "javascript get values by a key in array"

1

find the key of a value in array js

Object.keys(array).find(item => array[item].id === modifiedItem.id)
Posted by: Guest on October-12-2021
1

javascript object get value by key in array

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find((o, i) => {
    if (o.name === 'string 1') {
        arr[i] = { name: 'new string', value: 'this', other: 'that' };
        return true; // stop searching
    }
});

console.log(arr);
Posted by: Guest on May-08-2020

Code answers related to "javascript get values by a key in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language