javascript
Create fixed length array with blank values in it Javascript
Initialize an array in javascript of fixed length which has all blank values in it
var my_arr = Array(7).fill('');
console.log(my_arr);
In the code snippet, we have created an array which contains 7 items in it. We have used .fill() method of array to put blank values to it. You can also use custom values that you want to fill your array with. You can check a working example demo for the avove code as below.
Was this helpful?
Similar Posts
- Break an array into fixed length array groups using lodash in Javascript
- Lodash - Flatten an array to a fixed depth
- Assign fixed width to the columns of bar chart in Chart.js
- Assign a fixed height to chart in Chart.js
- Get all values from an array which does not exist in other array Lodash
- Get the sum of array values using Javascript - Solved
- Remove duplicate values from an array in Javascript