Answers for "check if var is object or array javascript"

13

Javascript is object array

var colors=["red","green","blue"];

if(Array.isArray(colors)){
    //colors is an array
}
Posted by: Guest on July-22-2019
-1

Check if an array contains a object in javascript

const list = [{
    'name': 'John Doe',
    'email': '[email protected]'
}, {
    'name': 'Jane Doe',
    'email': '[email protected]'
}];

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

const result = list.some(e => isEqual(e, {
    'name': 'John Doe',
    'email': '[email protected]'
}));

console.log(result); // true
Posted by: Guest on April-06-2022

Code answers related to "check if var is object or array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language