[JS] – How to compare the values of two objects ?

Javascript function

Write a function, deepEqual, that takes two values and returns true only if they are the same value or are objects with the same properties whose values are also equal when compared with a recursive call to deepEqual.

var obj = {here: {is: “an”}, object: 2};
console.log(deepEqual(obj, obj));
// → true
console.log(deepEqual(obj, {here: 1, object: 2}));
// → false
console.log(deepEqual(obj, {here: {is: “an”}, object: 2}));
// → true

Node : module to do it

Via node JS you can use : https://www.npmjs.com/package/deep-equal

Node : Assert methods to compare two objects

If you are want comapare the objects for a test, you can use : https://nodejs.org/api/assert.html

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s