Categories
JavaScript Answers

How to push to multidimensional array with JavaScript?

Spread the love

Sometimes, we want to push to multidimensional array with JavaScript.

In this article, we’ll look at how to push to multidimensional array with JavaScript.

How to push to multidimensional array with JavaScript?

To push to multidimensional array with JavaScript, we call push with the array.

For instance, we write

const valuesToPush = Array();
valuesToPush[0] = productID;
valuesToPush[1] = itemColorTitle;
valuesToPush[2] = itemColorPath;

cookieValues.push(valuesToPush);

to create the valuesToPush array with some values.

Then we call push on the cookieValues array to append the valuesToPush array with push.

Conclusion

To push to multidimensional array with JavaScript, we call push with the array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *