ES6 introduces Array.prototype.fill
. It can be used like this:
new Array(len).fill(0);
Not sure if it’s fast, but I like it because it’s short and self-describing.
It’s still not in IE (check compatibility), but there’s a polyfill available.
More Related Contents:
- compare each 5 numbers of two array [closed]
- Convert string into several integer arrays [duplicate]
- How to get all the values associated with an object in array?
- Sort array of objects by string property value
- How to determine if Javascript array contains an object with an attribute that equals a given value?
- How to sort 2 dimensional array by column value?
- JQuery .each() backwards
- Why does javascript’s “in” operator return true when testing if 0 exists in an array that doesn’t contain 0?
- Add property to an array of objects
- How to update an “array of objects” with Firestore?
- How to randomize (shuffle) a JavaScript array?
- Copy array by value
- Reverse array in Javascript without mutating original array
- Sorting objects by property values
- Razor MVC Populating Javascript array with Model Array
- Fastest JavaScript summation
- How to find duplicate values in a JavaScript array of objects, and output only unique values?
- Using promise function inside Javascript Array map
- Javascript passing arrays to functions by value, leaving original array unaltered
- What does $(selector)[0] mean in jQuery?
- Get list of duplicate objects in an array of objects
- Change the value of an array changes original array JavaScript
- Returning only certain properties from an array of objects in Javascript [duplicate]
- Splicing a Javascript array from within the callback passed to forEach
- Sum two arrays in single iteration
- Array.size() vs Array.length
- Create array of all integers between two numbers, inclusive, in Javascript/jQuery
- What is the difference between “in operator” and “includes()” for JavaScript arrays
- Sorting an Array of JavaScript Objects a Specific Order (using existing function)
- default array values