从多维数组中删除特定的数组元素? [英] Deleting specific array element from multidimensional array?
本文介绍了从多维数组中删除特定的数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在遍历多维数组并删除特定的元素数组时遇到麻烦.我的多维数组看起来像这样:
I'm having trouble cycling through a multidimensional array and deleting a specific element array. My multidimensional array looks a little like this:
myArray = [["Tom", "161"], ["Dick", "29"], ["Harry", "46"]];
因此,如果我的数字为29.循环遍历此数组并删除第二个元素为29的array元素的最有效方法是什么?即[[Dick],"29"]
So if I have the number 29. What's the most efficient way to cycle through this array and delete the array element who's second element is 29? i.e. ["Dick", "29"]
推荐答案
var myArray = [["Tom", "161"], ["Dick", "29"], ["Harry", "46"]];
var myNewArray = myArray.filter(function(item){ return item[1] != 29 })
.filter使用本机代码循环遍历您的数组.当然,构建新的阵列可能比仅将一部分旧阵列进行测试要昂贵得多.
.filter uses native code to loop over your array. Building a new array could of course be more expensive than just cutting a part out of the old one, to be tested.
这篇关于从多维数组中删除特定的数组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文