Js one-dimensional array matches two-dimensional array

var a = ["1", "3", "5"];
var b = [
    { id: "1", name: "" },
    { id: "2", name: "" },
    { id: "3", name: "" },
    { id: "4", name: "" },
    { id: "5", name: "" },
    { id: "6", name: "" },

];

how to match [{id: "1", name: "Business"}, {id: "3", name: "Swimming"}, {id: "5", name: "Leisure"},]

Nov.10,2021

var arr = b.filter(e=>{
 return a.includes(e.id) 
})
 
 console.log(arr)  

clipboard.png






b.filter(item=>a.indexOf(item.id)!==-1)

b id a.indexOf(item.id) biditem.id aindexOf-1

clipboard.png


const mapData = (a, b) => {
  return b.filter(item => {
      return a.includes(item.id)
    })
}

</span>

filterES5Polyfill

if (typeof Array.prototype.filter != "function") {
  Array.prototype.filter = function (fn, context) {
    var arr = [];
    if (typeof fn === "function") {
       for (var k = 0, length = this.length; k < length; kPP) {
          fn.call(context, this[k], k, this) && arr.push(this[k]);
       }
    }
    return arr;
  };
}
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-1e53752-45225.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-1e53752-45225.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?