lodash compare two arrays lodash compare two arrays The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke etc even without using any built-in objects. Other May 13, 2022 9:01 PM social proof in digital marketing. Underscore.js _.intersection() Function - GeeksforGeeks Other May 13, 2022 9:02 PM coconut. 3 Answers Sorted by: 4 The non performant approach would be array1.filter (elm1 => { return array2.find (elm2 => elm2.associatedID === elm1).length === 1 }) If your arrays are big, you could sort both arrays according to id and associatedID and run a for loop on both of them to somehow return result Share Improve this answer You can get it using lodash function _.intersection (). The order and references of result values are determined by the first array. A value is considered empty unless it's an arguments object, array, string. For example, the intersection of arrays [1,2,3,4] and [3,4,5] is [3,4]. compare two objects javascript lodash // program to compare two arrays function compareArrays (arr1, arr2) { // compare arrays const result = JSON . _.intersection([arrays]) source npm package. Lodash - zipObject method - Adglob Infosystem Pvt Ltd lodash intersection of two arrays of objects It is same as the intersection function in lodash only difference is that it accepts a comparator which is invoked to compare elements of arrays. Output (Object) − Returns the new object. _.intersectionWith - Lodash Docs v4.17.11 _.intersectionWith ( [arrays], [comparator]) This method is like _.intersection except that it accepts comparator which is invoked to compare elements of arrays. Lodash Documentation how to compare two array of objects in lodash Code Example Union of Arrays in JavaScript - UsefulAngle Objects. This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself. Arguments. _.intersectionBy method in Lodash - Devsheet On many modern browsers, we can take advantage of the ES6 Set object to speed things up. Lodash automatically uses Set when it's available. The reason is the flexibility to order the array from ascending or descending. Lodash provides functions to manipulate objects, to map objects and comparing objects. Other May 13, 2022 9:06 PM leaf node. let intersection = arr1.filter(x => arr2.includes(x _.intersectionBy method in Lodash - Devsheet The _.intersectionwith () method is used to take the intersection of the one or more arrays. How can we get intersection of two or multiple arrays.