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 :: [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]). 
Javascript :: axios all methods 
Javascript :: buffer nodejs 
Javascript :: moment clone 
Javascript :: socket..io 
Javascript :: angular Failed to make request to https://www.gstatic.com/firebasejs/releases.json 
Javascript :: DC League of Super-Pets 
Javascript :: serve static files from express 
Javascript :: path module js 
Javascript :: how to make alert in javascript 
Javascript :: check url if it has trailing slash 
Javascript :: javascript jquery map a range of numbers 
Javascript :: redux toolkit how to set empty initial state 
Javascript :: javascript typeof 
Javascript :: redux state proxy 
Javascript :: javascript spread operator 
Javascript :: text background fabricjs 
Javascript :: apollo clear cache for query 
Javascript :: assign input text value jquery 
Javascript :: sub array javascript 
Javascript :: js event div class adding 
Javascript :: using template literals to create html 
Javascript :: Ternary Operator react 3 Conditions 
Javascript :: discord.js make channel private 
Javascript :: null + undefined 
Javascript :: how to check if the number inputed is number 
Javascript :: ejs express layouts 
Javascript :: js get img under div 
Javascript :: Function is not defined - Uncaught ReferenceError 
Javascript :: compare between two arrays javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =