我有这样的数据:
[['Account 1', 122.00], ['Account 2', 342.33], ['Account 3', 103.32]]
我希望能够检查一个字符串是否存在于数组的第一个索引中,并在整个数组中找到它的索引。换句话说:
index = find(arr, 'Account 2') // This would return 1
JS 是否已经有内部可以做到这一点的东西?
最佳答案
在 ES6 中会有一个 findIndex
method这将做你想做的。您可能需要 shim it , 不过。
var arr = [['Account 1', 122.00], ['Account 2', 342.33], ['Account 3', 103.32]]
var index = arr.findIndex(function(item) { return item[0] == 'Account 2'; }) // 1
关于javascript - 使用 Javascript 在数组数组中搜索第一个索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29398052/