Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

compare object array equals

// Compare Objects
const objectsEqual = (o1, o2) =>
    Object.keys(o1).length === Object.keys(o2).length 
        && Object.keys(o1).every(p => o1[p] === o2[p]);

const obj1 = { name: 'John', age: 33};
const obj2 = { age: 33, name: 'John' };
const obj3 = { name: 'John', age: 45 };
        
console.log(objectsEqual(obj1, obj2)); // true
console.log(objectsEqual(obj1, obj3)); // false

// Compare Object Arrays
const arraysEqual = (a1, a2) => 
   a1.length === a2.length && a1.every((o, idx) => objectsEqual(o, a2[idx]));

console.log(arraysEqual(arr1, arr2)); // true
console.log(arraysEqual(arr1, arr3)); // false
Comment

PREVIOUS NEXT
Code Example
Javascript :: lowercase to uppercase in javascript 
Javascript :: normalize javascript 
Javascript :: response.json() promise pending 
Javascript :: Use Multiple Conditional Ternary Operators Javascript 
Javascript :: how to rotate an array in javascript 
Javascript :: javascript textarea.append 
Javascript :: how to use the replace method in javascript 
Javascript :: remove .html from url express js 
Javascript :: how to return a factorial in javascript 
Javascript :: how to get an array from another script in js 
Javascript :: sanitizer content nodejs 
Javascript :: Moment.js: Date between dates 
Javascript :: usereducer example 
Javascript :: how to get a user input in js 
Javascript :: Next js window is not defined solution 
Javascript :: first letter uppercase js 
Javascript :: react webpack.config.js example 
Javascript :: fs.readfile 
Javascript :: how to remove property from object javascript 
Javascript :: http request javascript 
Javascript :: webpack-bundle-analyzer react 
Javascript :: fivem player json 
Javascript :: express receive post data 
Javascript :: xmlhttprequest js 
Javascript :: add array to array js 
Javascript :: reverse array javascript 
Javascript :: import react 
Javascript :: react testing library for hooks 
Javascript :: what is polyfills in angular 
Javascript :: how to use saved image on react 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =