0

I need to get the ID’s from arr1 that match names in arr2 and replace/add these name ID pairs into arr3.

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’, }]

arr2: [{ name: ‘one’, }, { name: ‘two’, }, ]`

This would be result that needs to get pushed into a third array replacing the name elements with both names and ids.

arr3: [{ id: [1234, 12345], name: ‘one’, }, { id: [1270, 67812], name: ‘two’, }

ob1
  • 21
  • 4
  • This is closest I've come to a solution, but only works if user selected one option. `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 17 '17 at 00:31
  • and you want us to...? SO is not a code-writing service. Please post the code you've written in your question and any results, both expected and actual. – jmoon Aug 17 '17 at 00:34
  • Additional Context. This is HTML. User is selecting options with just name and do not want to present those ID's, but need them to make an HTTP put after data entry is complete. ` Services <{{service.name}} ` – ob1 Aug 17 '17 at 00:35
  • **UPDATE** Here is working example, but I need to get the ID's from "Array". Does anyone know how to do that? **var array** = [{id :1, name :"test1"},{id :2, name :"test2"},{id :3, name :"test3"},{id :4, name :"test4"}]; **var anotherOne** = [{name :"test2"}, {name :"test4"}]; `var filterResult = anotherOne.filter(myCallBack); function myCallBack(el){ return array.indexOf(el) < 0; } console.log('filterResult:', filterResult);` – ob1 Aug 17 '17 at 11:59

0 Answers0