如何返回已删除的对象?

时间:2015-05-18 22:08:02

标签: javascript arrays

我希望test [0]不受影响,但我想从函数中删除test [1]。这就是我想到的。

var example = function(data){
  this.information = data;

  delete this;
  return this;
}

test[1] = example("hello");

1 个答案:

答案 0 :(得分:1)

Array.splice

是你的朋友。

var arr = ["a", "b", "c", "d"];
arr.splice(1, 1);

// Output: ["a", "c", "d"]

进一步阅读:https://msdn.microsoft.com/library/wctc5k7s%28v=vs.94%29.aspx