Categories
JavaScript Answers

How to declare an array in JavaScript?

Spread the love

Sometimes, we want to declare an array in JavaScript.

In this article, we’ll look at how to declare an array in JavaScript.

How to declare an array in JavaScript?

To declare an array in JavaScript, we can use the array literal syntax.

For instance, we write

const x = [];
const y = [10];

to declare the empty array x.

And we declare the array y with 10 inside.

Conclusion

To declare an array in JavaScript, we can use the array literal syntax.

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 *