Q:

Write a JavaScript program to compare two objects to determine if the first one contains equivalent property values to the second one

0

Write a JavaScript program to compare two objects to determine if the first one contains equivalent property values to the second one.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

//#Source https://bit.ly/2neWfJ2
const matches = (obj, source) =>
  Object.keys(source).every(key => obj.hasOwnProperty(key) && obj[key] === source[key]);
console.log(matches({ age: 25, hair: 'long', beard: true }, { hair: 'long', beard: true })); // true
console.log(matches({ hair: 'long', beard: true }, { age: 25, hair: 'long', beard: true })); // false
console.log(matches({ hair: 'long', beard: true }, { age: 26, hair: 'long', beard: true })); // false

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now