2

Is it possible to compare two JS Objects based on their properties no matter the values ?

For example :

var first = {
    a: 2,
    b: 3
}
var second = {
   a: 4,
   b: 5
}
console.log(first.hasPropertiesOf(second)); //true
Hicka
  • 157
  • 3
  • 16
  • 1
    If you knew how to enumerate all of an object's properties, would you still need help in solving this problem? – Scott Hunter Oct 22 '19 at 17:44
  • Object.keys(first).every(elem => Object.keys(second).includes(elem)) && Object.keys(second).every(elem => Object.keys(first).includes(elem)) – chevybow Oct 22 '19 at 17:46
  • 1
    Hacky solution: `JSON.stringify(Object.keys(first)) == JSON.stringify(Object.keys(second))` – Jacek Rojek Oct 22 '19 at 17:47

0 Answers0