Assign key value pair in each loop
I'm trying to assign key/value variable pairs to an array w/in an each loop, but keep getting undefined on line #6 on the second pass of the loop. My key (mylabel) & value (myvalue) are extracted from form inputs. I'm going to post this to a php file to send out the responses.
- var arck = 0;
- $('all my form targets').each(function() {
- var mylabel = some text;
- var myvalue = some text;
- if (arck == 0) {var post_data = new Array(); arck = 1}
- post_data[mylabel] = myvalue;
- });
Simple example of array, after looping through 2 inputs:
- post_data [
- {name : some text},
- {email : some text2}
- ]
How do I assign the key/value pairs ?