Javascript examples for Array:map
Loop through sparse array and replace sparse values with map function
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// ww w.j a v a 2s . com var myarray = ['foo',, 'bar', , , , ]; function Fill(n, _default) { return Array.apply(null,n).map(function(val) { console.log("val"+val); return val || _default; }); } var newa = Fill(myarray, "default"); console.log(JSON.stringify(newa)); } </script> </head> <body> </body> </html>