0

I've got something like this:

var test={
    arr : [1,2],
    number : 5
}

(test.arr).push(3);

It says: "Uncaught TypeError: Cannot read property 'arr' of undefined ". So how can i push a number or string into 'test.arr'?

4

1 回答 1

2

you need to do:

test.arr.push(3);

so:

var test={
    arr : [1,2],
    number : 5
}
test.arr.push(3);
console.log( test.arr ); //gives [1,2,3]
于 2013-11-06T04:06:06.177 回答