How to push an array into an array inside an object in Javascript?
Question
There is an object like below:
1 | var myObj = { |
And one array is var newArray = ['A', 'B'];
I want to add newArray
into arrayOne: []
, the result should be like below
1 | { |
What should I do?
Answer
There are two ways to add newArray
inside arrayOne
of myObj
.
obj.arrayOne.push(newArray);
obj['arrayOne'].push(newArray);
Reference
This is the end of post