programming-examples/js/Array/Write a JavaScript function to create a specified number of elements and pre-filled string value array..js

7 lines
216 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function array_filled(n, val)
{
return Array.apply(null, Array(n)).map(String.prototype.valueOf,val);
}
console.log(array_filled(3, 'default value'));
console.log(array_filled(4, 'password'));