Reputation: 7240
I have a bunch of input text fields that are in the same class emps_l
with different values. I want to loop through the all elemets with that class and store the values in to an array!
Bellow is what I have done:
var emps = new Array();
$.each(($(".emps_l").val()),function()({
emps.push($(".emps_l").val());
});
console.log(emps);
I am totally lost, Any help will be highly appreciated!
Upvotes: 0
Views: 210
Reputation: 21233
var emps = []; // This is considered slightly faster than new array
$('.emps_1').each(function(){
emps.push(this.value);
});
console.log(emps);
Upvotes: 1
Reputation: 766
use this :
var emps = new Array();
$.each(($(".emps_l:input").val()),function(index , item )({
emps.push($(item ).val());
});
console.log(emps);
Upvotes: 1
Reputation: 388316
You can use .map() along with this.value
to create the array
var emps = $(".emps_l").map(function () {
return this.value
}).get()
Upvotes: 4