在javascript中从数组的所有子数组中删除特定元素的最快方法是什么

时间:2014-11-26 10:33:40

标签: javascript arrays

我有一个这样的数组:

"output" : [
  {
    "zip":35004,
    "state":"AL",
    "City":"Acmar",
    "lat":33.584132,
    "lng":-86.51557
  },
  {
    "zip":35005,
    "state":"AL",
    "City":"Adamsville",
    "lat":33.588437,
    "lng":-86.959727
  }
]

现在我如何删除' lat'而且' long'来自所有子阵列。我想要一个像这样的输出:

"output" : [
  {
    "zip":35004,
    "state":"AL",
    "City":"Acmar"            
  },
  {
    "zip":35005,
    "state":"AL",
    "City":"Adamsville"           
  }
]

最快的方法是什么?

1 个答案:

答案 0 :(得分:4)

我想

for (var i = 0; i < row.length; i++) {
     delete row[i].lat;
     delete row[i].long;
}

For比forEach更快,使用delete显然是