嵌套数组 - 如何向嵌套JavaScript数组添加一行元素

时间:2018-06-08 14:24:30

标签: javascript

我想添加行

    ['2008',777,333]

to var fun并维护结构:

var fun = [
    ['Year', 'Sales', 'Expenses'],
    ['2004',  1000,      400],
    ['2005',  1170,      460],
    ['2006',  660,       1120],
    ['2007',  1030,      540]
         ];

使用push或concat似乎破坏了结构。可以这样做吗?

1 个答案:

答案 0 :(得分:0)

fun.push(['2008', "1033", "554"]) //to add whole row
fun[2].push('555') // to add item into row 3 as the last item
相关问题