0

我有 2 个变量数组:

var a = [22, 34, 56,22]
var b = [red, blue, yellow, gray ]

我检查数组的索引a,其中有值22,索引是0然后3我打印var b[0]b[3]我得到RedGray

我如何使用/在 Jquery 中执行此操作?

4

1 回答 1

0

你是这个意思吗?

  var a = [22, 34, 56, 22];
  var b = ["red", "blue", "yellow", "gray"];
  var input = 22;

  var matches = $.map(a, function (o, i) { //Using map to get the array of matches, apply map on a
      if (o === input) return b[i]; //check if the value is equal to input, if so return the value from array b for the same index
  })
  console.log(matches); //matches will be array of matches

小提琴

于 2013-09-28T03:33:39.507 回答