Js algorithm problem

let arr1 = [
    {
        label:""
        value:"1"
    },
    {
        label:"",
        value:"2"
    },
    {
        label:"",
        value:"3"
    }
 ]

let arry2 = ["1","2"]

let resArry = ?

console.log(resArry)   //  

the value in arry2 can correspond to the value in arry1, then put it into resArry and finally print out Zhang San and Li Si

.

how to achieve this?

Apr.11,2021

let resArry = arr1.filter(o=>arry2.indexOf(o.value)>-1).map(o=>o.label);
console.log(resArry);

you can just write a loop, or I don't understand what you mean


let obj1 = arr1.reduce((iter, val) => (iter[val.value] = val.label, iter), {});
let resArry = arry2.map(v => obj1[v]);

var arr1 = [
  {
    label: '',
    value: '1'
  },
  {
    label: '',
    value: '2'
  },
  {
    label: '',
    value: '3'
  }
]

var arr2 = ['1', '2']
var resArry=[];
for(var i=0;i<arr1.length;iPP){
  for(var j=0;j<arr2.length;jPP){
    if(arr2[j]==arr1[i].value){
      arrtemp.push(arr1[i].label)
    }
  }
}
console.log(resArry);

refer to ezmo and change it

let resArry = arr1.filter(o=>arry2.includes(o.value)).map(o=>o.label).join('')

var arr1 = [

]
{
    label:'',
    value:'1',
},
{
    label:'',
    value:'2',
},
{
    label:'',
    value:'3',
}

];

var arr2 =

var resArry = [];

for (var item of arr1) {

for(var str of arr2){
    if(str == item.value){
        resArry.push(item.label)
    }
}

}
console.log (resArry)

Menu