I have called serialize on array
inputColl.serialize();
How to loop to it and print values?
I have called serialize on array
inputColl.serialize();
How to loop to it and print values?
jQuery.each()
(not the same as jQuery().each()
) can iterate over nearly any iterable object.
cpharmston and cletus have solid approaches. I'll offer a plain JavaScript approach and an approach you should not use:
How to loop through an array using plain ol' JavaScript:
var arr = inputColl.serialize();
for(var i = 0; i < arr.length; ++i)
{
//do something with arr[i];
}
Don't confuse the loop above with this one:
var arr = inputColl.serialize();
for(var i in arr)
{
}
The JavaScript for/in statement loops through an object's properties. This is a very different operation than looping through an array's contents, but it is a common mistake to make. This is especially common if you use languages like C# and are expecting behavior similar to its foreach construct.