0

I'm doing a simple check that returns no data using _.intersection. console.log('intersection', _.intersection(arr1, arr2)); If I use _.isEqual it correctly returns "false" as there is only one value in arr1 that is in arr2. Does anyone know why _.isEqual would work and not _.intersection?

ob1
  • 21
  • 3
  • post your array – Sajeetharan Aug 16 '17 at 02:56
  • `arr1: [{ id: [1234,12345], name: ‘one’, }, { id: [1270,67812], name: ‘two’, }, { id: [4970,5170], name: ’three’, }, { id: [02413,02613], name: ‘four’, }, { id: [8970], name: ‘five’, }, { id: [7170,6570,6370], name: ‘six’, }, { id: [8170,22012,4578,33613], name: ‘seven’, }, { id: [21812,6170,20412,42812,22012,8170], name: ‘eight’, }]` – ob1 Aug 16 '17 at 04:04
  • `arr2: [{ name: ‘one’, }, { name: ‘two’, }, { }]` – ob1 Aug 16 '17 at 04:09
  • I'm trying to get the ID's from "arr1" based on names in "arr2" and insert them in another array which includes both names and id's. For some reason every solution I've come across doesn't work in angular2. – ob1 Aug 16 '17 at 04:14
  • The last thing I've tried was this:[link](https://derickbailey.com/2015/09/23/how-to-get-the-difference-between-two-arrays-as-a-distinct-list-with-javascript-es6/) it doesn't work as angular doesn't understand the .has method when using .filter. – ob1 Aug 16 '17 at 04:19
  • Also, tried these approaches: [link](https://stackoverflow.com/questions/32965688/comparing-two-arrays-of-objects-and-exclude-the-elements-who-match-values-into) – ob1 Aug 16 '17 at 04:22
  • **UPDATE** I got this to work doing the following. `var temp = arr2 var temp1 = arr1 var filterResult = temp1.filter(function(e){ return e.name == temp; }); console.log('filterResult:', filterResult); this.selected.push(filterResult);` – ob1 Aug 16 '17 at 06:10
  • **NEW PROBLEM** -- **this.selected.push(filterResult);** need to replace the existing "name" with "name" and "id" i pushed to above array or just add "id" to it. Currently, this just adds another entry which won’t work correctly .. It seems there should be an easier way to do this. – ob1 Aug 16 '17 at 06:15

0 Answers0