Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

find particular object from array in js

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

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Comment

find particular object from array in js

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

PREVIOUS NEXT
Code Example
Javascript :: jquery submit form 
Javascript :: connecting nodejs using mongoose 
Javascript :: background image in react from variable 
Javascript :: localstorage vs sessionstorage 
Javascript :: get element by id like javascript 
Javascript :: instantiate template playcanvas 
Javascript :: how to make input field empty in javascript 
Javascript :: javascript get multiple elements by id 
Javascript :: how to use a fixed time zone in nodejs 
Javascript :: how to check if all inputs are not empty with javascript 
Javascript :: query string from object js 
Javascript :: javascript select text in element 
Javascript :: localstorage setitem 
Javascript :: how to find hcf of 2 numbers in javascript 
Javascript :: react prevent component from update once mounted 
Javascript :: how would you check if a number is an integer in javascript 
Javascript :: execute a function at a certain time of day js 
Javascript :: javascript text replace 
Javascript :: how can ic get the id of div jq 
Javascript :: webpack config minify 
Javascript :: express.urlencoded extended true or false 
Javascript :: updating a key value on javascript object es6 
Javascript :: js string count 
Javascript :: how to increment counter button click in js 
Javascript :: react read multiple files with filereader 
Javascript :: how to use uniqid 
Javascript :: loop through an array in js 
Javascript :: get element of an array inside another array 
Javascript :: javascript format date mm/dd/yyyy 
Javascript :: finddomnode is deprecated in strictmode 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =