Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在数组中的某个位置将字符串推入数组_Arrays_Node.js_Push - Fatal编程技术网

Arrays 在数组中的某个位置将字符串推入数组

Arrays 在数组中的某个位置将字符串推入数组,arrays,node.js,push,Arrays,Node.js,Push,如何将字符串推入数组中的数组 var outerArray = [[]] outerArray.push('test1') outerArray.push('test2') outerArray[0] = outerArray[0].push('test3') console.log(outerArray[0][0]) 这只返回未定义的似乎要在位置0处创建一个数组,包括该索引处的上一项和一个新项。这将有助于: outerArray[0] = [outerArray[0], 'test3'

如何将字符串推入数组中的数组

var outerArray = [[]]

outerArray.push('test1')
outerArray.push('test2')

outerArray[0] = outerArray[0].push('test3')

console.log(outerArray[0][0])

这只返回未定义的

似乎要在位置0处创建一个数组,包括该索引处的上一项和一个新项。这将有助于:

outerArray[0] = [outerArray[0], 'test3']

另外,正如您所知,push返回一个已被推送的项目。

您发布的代码无效:-/@FabianLauer-ups,已更新
const innerArray = outerArray[0];
const pushedString = innerArray.push('testString');