1

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.

2
  • Why don't you want to use each? Commented May 28, 2014 at 8:30
  • I have no problem with each. I'm just interested in jQuery provided another way for an array setter. Commented May 28, 2014 at 8:32

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Paul, yes, that's what my answer does. I'll clarify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.