Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push array into another array as one element

Tags:

People also ask

How do I push one array of elements to another array?

The arr. push() method is used to push one or more values into the array. This method changes the length of the array by the number of elements added to the array. Parameters: This method contains as many numbers of parameters as the number of elements to be inserted into the array.

How do you push an element into a new array?

JavaScript Array push()The push() method adds new items to the end of an array. The push() method changes the length of the array. The push() method returns the new length.

Can an array be an element of another array?

An array is said to fit into another array if by arranging the elements of both arrays, there exists a solution such that the ith element of the first array is less than or equal to ith element of the second array.


I'm new in JS, can't find solution to do something like that

var arr = [0];
var elem = [1, 2, 3];
???
console.log(arr); // shows [0, [1, 2, 3]];

I've tried with .push(elem), JS decides that I passed array of values (not a single one), and concatenate content of arr and elem arrays, so that the result is [0, 1, 2, 3]