Hi, Comparing two objects in javascript is anything but straightforward. This is the "authoritative" response on SO: https://stackoverflow.com/questions/201183/how-to-determine-equality-for-two-javascript-objects
The easiest solution is to use Underscore, which has _.isEqual(obj1, obj2); (It's a "simple" solution only in theory... have a look at the implementation! http://underscorejs.org/docs/underscore.html#section-113 Hope this helps, Merc. On Tuesday, 12 December 2017 16:59:03 UTC+8, udhay prakash pethakamsetty wrote: > > Hi all, > > I am new to nodejs. > > I have two arrays of objects. > > array1 = [ > { > id: '1', // unique key > name: 'apple' > }, > { > id: '2', // unique key > name: 'mango' > } > ]; > > array2 = [ > { > id: '1', // unique key > name: 'apple' > }, > { > id: '3', // unique key > name: 'car' > } > ]; > > I want to get the difference objects. > i.e., > array1 - array2 =---> result > > { > id: '2', // unique key > name: 'mango' > } > Similarly, > array2 - array1 =---> result > > { > id: '3', // unique key > name: 'car' > } > > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/eafa670b-6aa5-43dd-be1d-16b63cdc1538%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
