var data = [{value:'1',text:'1'},
{value:'2',text:'2'},
{value:'3',text:'3'},
{value:'4',text:'4'},
{value:'5',text:'5'},
{value:'6',text:'6'}];
var arr = ['1','2','4']
var arr1 = []
data.map(e=>{
if(arr.includes(e.value))arr1.push(e.text)
})
console.log(arr1)
// :filtermap includes ES7indexOf
var data = [{value:'1',text:'1'},
{value:'2',text:'2'},
{value:'3',text:'3'},
{value:'4',text:'4'},
{value:'5',text:'5'},
{value:'6',text:'6'}];
var arr = ['1','2','4']
var result = data.filter(e=>{
return arr.includes(e.value)
}).map(el => el.text);
console.log(result); // ["1", "2", "4"]
var data = [{ value: '1', text: '1' },
{ value: '2', text: '2' },
{ value: '3', text: '3' },
{ value: '4', text: '4' },
{ value: '5', text: '5' },
{ value: '6', text: '6' }];
var arr = ['1', '2', '4']
let newArr=data.reduce((prev,cur)=>{
arr.includes(cur.value)&&prev.push(cur.text)
return prev
},[])
console.log(newArr); //(3)["1", "2", "4"]
function test() {
var values = ['1','2','4'];
var data = [{value:'1',text:'1'},
{value:'2',text:'2'},
{value:'3',text:'3'},
{value:'4',text:'4'},
{value:'5',text:'5'},
{value:'6',text:'6'}];
let result = new Map(data.map(key=>[key.value, key.text]))
let temp = new Set()
values.map((item)=>{
if (result.has(item)) {
temp.add(result.get(item))
}
})
return [...temp.values()]
}