Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array contains object in javascript

array.findIndex((obj) => obj.id === obj.id) !== -1
Comment

javascript object array contains

if (vendors.findIndex(item => item.Name == "Magenic") == -1) {
  //not found item
} else {
  //found item 
}
Comment

check object in array javascript

var obj = {a: 5};
var array = [obj, "string", 5]; // Must be same object
array.indexOf(obj) !== -1 // True
Comment

javascript includes check object

let hasMagenicVendor = vendors.some( vendor => vendor['Name'] === 'Magenic' )
Comment

Check if an array contains a object in javascript

const john = {
    'name': 'John Doe',
    'email': 'john.doe@example.com'
};
const jane = {
    'name': 'Jane Doe',
    'email': 'jane.doe@example.com'
};

const list = [john, jane];
let result = list.includes(john);

console.log(result); // true
Comment

Check if an array contains a object in javascript

const list = [{
    'name': 'John Doe',
    'email': 'john.doe@example.com'
}, {
    'name': 'Jane Doe',
    'email': 'jane.doe@example.com'
}];

const isEqual = (first, second) => {
    return JSON.stringify(first) === JSON.stringify(second);
}

const result = list.some(e => isEqual(e, {
    'name': 'John Doe',
    'email': 'john.doe@example.com'
}));

console.log(result); // true
Comment

PREVIOUS NEXT
Code Example
Javascript :: conditional style prop react 
Javascript :: tab adds tab textarea javascript 
Javascript :: fetch Response object get content type 
Javascript :: js looping through array 
Javascript :: image preview 
Javascript :: jquery set select value 
Javascript :: componentwillunmount 
Javascript :: javascript set input value 
Javascript :: formdata array of objects 
Javascript :: angular pipe percentage 
Javascript :: how to know which button is clicked in jquery 
Javascript :: javascript convert a number in string 
Javascript :: how to remove a specific element from array in javascript 
Javascript :: loading 
Javascript :: scroll to top router link vue 
Javascript :: javascript generator function 
Javascript :: js key value array 
Javascript :: how to convert name to initials in javascript 
Javascript :: vue router refresh page not found 
Javascript :: jquery get 2nd child 
Javascript :: regex find first instace 
Javascript :: javascript edit form value 
Javascript :: how to convert set to a string in js 
Javascript :: how to remove more than one attribute using jquery 
Javascript :: shadowcolor liners in react native 
Javascript :: create new angular project with specific version 
Javascript :: usereducer react js 
Javascript :: how to export a constant in javascript 
Javascript :: determine if touch screen js 
Javascript :: this element in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =