You can use the fill
function on an array:
Array(24).fill(0)
Note: fill
was only introduced in ECMAScript 2015 (alias “6”), so as of 2017 browser support is still very limited (for example no Internet Explorer).
More Related Contents:
- Array.prototype.fill() with object passes reference and not new instance
- JavaScript: Difference between .forEach() and .map()
- Why can I add named properties to an array as if it were an object?
- How to extend an existing JavaScript array with another array, without creating a new array
- Is the order of elements in a JSON list preserved?
- JavaScript: How to join / combine two arrays to concatenate into one array?
- Maximum size of an Array in Javascript
- Sum JavaScript object propertyA values with the same object propertyB in an array of objects
- Merge 2 arrays of objects
- Convert string with commas to array
- How might I extract the property values of a JavaScript object into an array?
- Sampling a random subset from an array
- Comparing two arrays of objects, and exclude the elements who match values into new array in JS
- How to check if a string array contains one string in JavaScript? [duplicate]
- Count duplicates within an Array of Objects
- MongoDB select where in array of _id?
- Search array of objects for entry matching variable and check if it matches other fields
- How can I perform an inner join with two object arrays in JavaScript?
- How to get the first element of an array?
- Javascript 2d array indexOf
- How to merge each object within arrays by index?
- Unexpected comma using map()
- Counting occurrences of particular property value in array of objects [duplicate]
- Convert js Array() to JSon object for use with JQuery .ajax
- How to find a value in an array of objects in JavaScript?
- Javascript: hiding prototype methods in for loop?
- If I set only a high index in an array, does it waste memory?
- looping through arrays of arrays
- Add key value pair to all objects in array
- javaScript: Can a comma occur after the last set of values in an array?