15
rated 0 times
[
19]
[
4]
/ answers: 1 / hits: 18490
/ 10 Years ago, wed, march 19, 2014, 12:00:00
I imagine this is similar to array padding, but I wonder if it can be simplified at all.
var arr = [1,2,3],
x = 5;
for (var i=0; i<x; i++) {
arr.push(x);
}
console.log(arr);
//=> [1, 2, 3, 5, 5, 5, 5, 5]
Is there any way to do this without using the for loop?
Update
Even though there's mover clever solutions, the for-loop seems to be the most performant
More From » arrays