OK this would return an array of node values
var vals = $('.items').map(function () { return $(this).val(); }).get();
What's the other way around, what's the setter from an array without the usual iteration including each?
Having an array and set each value to the corresponding node from the collection $('.items') using the api.
asked May 28, 2014 at 8:27
kidwon
4,5265 gold badges31 silver badges46 bronze badges
1 Answer 1
Typically you would use the form of val() that takes a function:
$(".items").val(function(index, currentValue) {
return vals[index];
});
The code above will iterate over the elements matching .items, and set their values to the respective array elements.
answered May 28, 2014 at 8:31
Frédéric Hamidi
264k42 gold badges497 silver badges486 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Frédéric Hamidi
@Paul, yes, that's what my answer does. I'll clarify.
lang-js
each?each. I'm just interested in jQuery provided another way for an array setter.