Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript object equals

function isEqual(obj1, obj2) {
  const props1 = Object.getOwnPropertyNames(obj1);
  const props2 = Object.getOwnPropertyNames(obj2);
  if (props1.length != props2.length) {
      return false;
  }
  for (let i = 0; i < props1.length; i++) {
      let val1 = obj1[props1[i]];
      let val2 = obj2[props1[i]];
      let isObjects = isObject(val1) && isObject(val2);
      if (isObjects && !isEqual(val1, val2) || !isObjects && val1 !== val2) {
          return false;
      }
  }
  return true;
}
function isObject(object) {
  return object != null && typeof object === 'object';
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: return longest string from array 
Javascript :: jquery trigger link click 
Javascript :: nextjs socket 
Javascript :: how to remove a part of a string javascript 
Javascript :: javascript change all anchors color 
Javascript :: mongoose connect to URL of atlas 
Javascript :: javascript print all items in array 
Javascript :: react check if focused 
Javascript :: javascript redirect to relative url 
Javascript :: redirect to page in javascript 
Javascript :: redirect to html page in javascript 
Javascript :: javascript array distinct 
Javascript :: sort array of objects javascript 
Javascript :: browserrouter react 
Javascript :: mute video javascript 
Javascript :: workbox push notifications 
Javascript :: discord js duplicate channel 
Javascript :: node js util promisify 
Javascript :: File is a CommonJS; it may be converted to an ES6 module 
Javascript :: react overflow scroll 
Javascript :: js date after 1 year 
Javascript :: js not equal to null 
Javascript :: javascript object first key 
Javascript :: js set url params 
Javascript :: append sibling javascript after first child 
Javascript :: last position of array javascript 
Javascript :: system collections generic list to javascript array 
Javascript :: convert iso 8601 to utc javascript 
Javascript :: console.table javascript 
Javascript :: first digit javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =