Tags
Asked 3 years ago
9 Jun 2021
Views 319
jignesh

jignesh posted

How can I push array inside array

How can I push array inside array
pratik

pratik
answered Mar 1 '23 00:00

To push an array inside another array, you can use the push() method in JavaScript . Here's an example:



let a= ['a', 'b', 'c']; // an array
let b= ['d', 'e', 'f']; // another array

// push a into b
a.push(b);


console.log(a); // Output: ['a', 'b', 'c', ['d', 'e', 'f']]

In the example above, we first declare two arrays arr1 and arr2. Then, we use the push() method on arr1 and pass arr2 as an argument to push arr2 inside arr1. The resulting array will have arr2 nested inside arr1 as a single element.
Post Answer