2017-06-15 62 views
-3

如何將字符串推送到數組中的數組中?將字符串插入陣列中某個位置的數組

var outerArray = [[]] 

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

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

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

這只是返回undefined

+0

您發佈的代碼不起作用: -/ –

+0

@FabianLauer oups,更新了它 – Bostrot

回答

0

好像你要創建在包括指數在上一個項目和一個新的位置0的數組。這將工作:

outerArray[0] = [outerArray[0], 'test3'] 
0
const innerArray = outerArray[0]; 
const pushedString = innerArray.push('testString'); 

此外,如你所知,推返回已推入的項目。

相關問題