如何将数组推送到数组? (二维数组javascript codeigniter)

时间:2017-06-16 14:41:37

标签: javascript arrays codeigniter

抱歉,我是一名javascript初学者。 我的数据有问题。 我希望有人可以给我解决方案(在这里有js的文档或答案)。 我有阵列

var array1 = ["you","they","them","he","she","it"];
var array2 = ["we","us","me","I"];

我有一个数组来保存那些数组

var data = [][]; //I don't know how to write.

如何在数据中保存array1和array2? 以及如何打印这些数据? 感谢。

2 个答案:

答案 0 :(得分:2)

首先创建一个数组

var arr = [];

并简单地将其他数组推送到它

arr.push(["you","they","them","he","she","it"]);
arr.push(["we","us","me","I"]);

您可以检索单个项目

var youVar = arr[0][0]; // has value "you"

答案 1 :(得分:1)

试试这个。



var array1 = ["you","they","them","he","she","it"];
var array2 = ["we","us","me","I"];

var mergedArray = [];
mergedArray.push(array1);
mergedArray.push(array2);
console.log(mergedArray); //To access the merged array
console.log(mergedArray[0]); //To access first array
console.log(mergedArray[0][0]); //To access element inside first array