Categories
JavaScript Answers

How to initialize an array’s length in JavaScript?

Spread the love

To initialize an array’s length in JavaScript, we set the array’s length property.

For instance, we write

const test = [];
test.length = 4;

to set the length property of the test array to set its length to 4.

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 *