1

I have html form with names like ...name="bulk[]".... Is there way to get all values of bulk in array with jquery? Ex

$('[name*="bulk"]').val().join('|');// this is incorrect just to show how I need that
asked Sep 2, 2013 at 16:39
2

6 Answers 6

3

.map() is made for this purpose

var myarray = $('[name^="bulk"]').map(function(){
 return $(this).val()
}).get();
answered Sep 2, 2013 at 16:40
Sign up to request clarification or add additional context in comments.

2 Comments

it says join is not a function
I think what you want is to use join on a native js array, see my answer - you just need the additional call to 'get'
1

You can use map and get to turn it to a true array!

$('[name*="bulk"]').map(function(){
 return $(this).val();
}).get();
answered Sep 2, 2013 at 16:42

Comments

0

Try the following

var obj = [];
$('[name^="bulk"]').each(function(){
 obj.push($(this).val());
});
answered Sep 2, 2013 at 16:41

Comments

0

You can use .map() to add the names

var myarray = $('[name^="bulk"]').map(function(){
return $(this).val()
}).get();
answered Sep 2, 2013 at 16:41

Comments

0
$elements = $(selector).map(function() { return $(this).val() });
var element_array = $.makeArray($elements);

This will make valid array from jQuery selector.

answered Sep 2, 2013 at 16:43

Comments

0

try this:

var arr = [];
$("[name*="bulk"] :input").each(function(){
 var input = $(this);
 arr.push(input.val())
});

It will get only input type fields

answered Sep 2, 2013 at 16:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.