Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. function isEqual(firstObj, secondObj) {
  2. const firstKeys = Object.keys(firstObj);
  3. const secondKeys = Object.keys(secondObj);
  4.  
  5. if (firstKeys.length !== secondKeys.length) {
  6. return false;
  7. }
  8.  
  9. return firstKeys.every(function (key) {
  10. return firstObj[key] === secondObj[key];
  11. });
  12. }
  13.  
  14. const first = {
  15. property: 'value',
  16. anotherProperty: 'another value'
  17. };
  18.  
  19. const second = {
  20. property: 'value',
  21. anotherProperty: 'another value'
  22. };
  23.  
  24. const third = {
  25. property: 'value',
  26. anotherProperty: 'one more value'
  27. };
  28.  
  29. isEqual(first, second); // true
  30. isEqual(second, third); // false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement