According to the key value, js selects the items that meet the conditions to form a new array.

topic description

there is an array, such as let arr = ["banana", "apple", "pear"]; , and then another array of objects:

let arr = ["",""""];


// 
let allArr = [
    {id:"001",name:"",price:"2"},
    {id:"002",name:"",price:"1"},
    {id:"003",name:"",price:"20"},
    {id:"004",name:"",price:"22"},
    {id:"005",name:"",price:"26"}
];


// :arr;
// 
let finalArr = [
    {id:"002",name:"",price:"1"},
    {id:"001",name:"",price:"2"},
    {id:"003",name:"",price:"20"}
];
Jan.10,2022

   arr.forEach((a) => {
       allArr.forEach((all) => {
          if(a === all.name){
             finalArr.push(all);
          }
       })
    })

  

allArr.filter (I = > arr.some (_ I = > i.name = _ i)). Sort ((a, b) = > arr.indexOf (a.name)-arr.indexOf (b.name) > = 0? 1:-1)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e96f6b-473ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e96f6b-473ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?