js 二维数组匹配另外一个数组的值

有一个二维数组和一个一维数组,根据一维数组提供的值,找到对应二维数组中的元素


二维数组 数字是编号

[

  ["1","商务"],

  ["2","健身"],

  ["3","游泳"],

  ["4","餐饮"],

  ["5","休闲"],

  ["6","住宿"]


]




[1,3,5]

对应 ["1","商务"]  ["3","游泳"] ["5","休闲"]


ABOUTYOU
浏览 368回答 1
1回答

皈依舞

Array.prototype.myFilter=function(ary){  return this.filter(function(item){     return  ary.indexOf(Number(item[0]))!=-1;  })}var a=[  ["1","商务"],  ["2","健身"],  ["3","游泳"],  ["4","餐饮"],  ["5","休闲"],  ["6","住宿"]];    var b=[1,3,5];    console.log(a.myFilter(b))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript