我正在尝试从二维数组arr拼接数组二。
var one = ["a","b"];
var two = ["c","d"];
var thr = ["e","f"];
var arr = [one,two,thr];
这是我的两次不成功的尝试:
1)
var rem = arr.splice(1,1);
alert(rem[0]);
// This alerts the entire array as one long string "c,d".
// The expected behavior is "c" (index 0 of the returned array _rem_).
2)
var rem = arr[1].splice(0);
alert(arr);
// The array _rem_ is now correct, but _arr_ is left with an empty index: "a,b,,e,f".
我有一个不太理想的解决方法,但我希望通过一个功能来实现这一点。
var test = arr[1].slice(0);
arr.splice(1,1);