I want to make a new array (of X elements) with all the elements set to 0.
X is set before.
Anyone could make the most compact and easy code for that? Thank you for your 
help.
            Asked
            
        
        
            Active
            
        
            Viewed 41 times
        
    -1
            
            
        
        The SuperCuber
        
- 171
 - 8
 
- 
                    @EdHeal Thanks for the negativity :D – The SuperCuber Feb 13 '15 at 19:48
 
1 Answers
1
            
            
        Just create a function:
function makeArray(size, defaultValue) {
    var arr = [];
    for (var i = 0; i < size; i++) arr.push(defaultValue);
    return arr;
}
var myArr = makeArray(10, 0);
        tymeJV
        
- 103,943
 - 14
 - 161
 - 157