Is there any other better way to fill up the array like :
var arr = [];
var i = 0;
$('select').children('option').each( function() {
arr[i++] = $(this).html();
});
4 Answers 4
using push() :
var arr = [];
$('select').children('option').each( function() {
arr.push($(this).html());
});
answered Jun 20, 2012 at 12:50
mgraph
15.3k4 gold badges43 silver badges76 bronze badges
Comments
var arr = [];
$('select option').html(function(i, html) {
arr.push(html);
});
answered Jun 20, 2012 at 12:55
thecodeparadox
87.2k22 gold badges143 silver badges164 bronze badges
Comments
Array.prototype.fill = function(value, length){
while(length--){
this[length] = value;
}
return this;
}
// example:
var coords = [].fill(0, 3);
answered Jul 18, 2013 at 11:47
Lajos Mészáros
3,8612 gold badges23 silver badges30 bronze badges
Comments
lang-js