我想按内容获取数组顺序号,我的数组如下所示:
[
[ '560134275538747403', 39953 ], <- 0
[ '411510958020624384', 36164 ] <- 1
] (ID) (VALUE)
要获取数组,我应该使用 ID(我已经有了),然后我需要的输出就是数字。
例如,'560134275538747403'
将为您提供 0
,'411510958020624384'
将为您提供 1
,并且。 ..
怎么做? ~谢谢。
最佳答案
你可以采取Array#findIndex
带有回调。
function findIndex(array, value) {
return array.findIndex(([v]) => v === value);
}
var array = [['560134275538747403', 39953], ['411510958020624384', 36164]];
console.log(findIndex(array, '560134275538747403')); // 0
console.log(findIndex(array, '411510958020624384')); // 1
关于javascript - 如何根据内容获取数组序号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57417739/