When using jQuery's serializeArray() on my form I get an array that looks like this:
[{
"name": "name",
"value": "1_filename.jpg"
}, {
"name": "caption",
"value": "1_caption"
}, {
"name": "name",
"value": "2_filename.jpg"
}, {
"name": "caption",
"value": "2_caption"
}, {
"name": "name",
"value": "3_filename.jpg"
}, {
"name": "caption",
"value": "3_caption"
}, {
"name": "name",
"value": "4_filename.jpg"
}, {
"name": "caption",
"value": "4_caption"
}]
But the rest of my code expects something more like this:
[{
"name": "1_filename.jpg",
"caption": "1_caption"
}, {
"name": "2_filename.jpg",
"caption": "2_caption"
}, {
"name": "3_filename.jpg",
"caption": "3_caption"
}, {
"name": "4_filename.jpg",
"caption": "4_caption"
}]
I'm new to manipulating arrays and objects like this and I'm not sure if there is already a convention that's used to convert the first to something similar to the second example.
My first guess is to just iterate by 2 and push them to a new object. I've tried iterating by one and checking the names but I'm having some trouble making sure the name and captions stay together correctly.
serializeArray()?