Reputation: 10256
I have var data = serializearray()
.
The output of data
is
[
{
name: "a",
value: "1"
},
{
name: "b",
value: "2"
},
{
name: "c",
value: "3"
},
]
How do i add more names and values to data after serializearray()
has been done.
Upvotes: 0
Views: 6103
Reputation: 23142
The output is just a Javascript array, so you can manipulate it as such.
To add another element: data.push({ name: "d", value: "4" });
To modify an existing element: data[0].name = "newName";
For more information, see the MDN docs for Array.
Upvotes: 7
Reputation: 227310
Push onto the array:
data.push({
name: 'd',
value: '4'
});
Or concat multiple arrays:
var newData = [{
name: 'd',
value: '4'
}];
data = data.concat(newData);
Upvotes: 2
Reputation: 255155
data.push({
name: 'foo',
value: 'bar'
});
And you even can pass several additional objects in one call:
data.push({
name: 'foo',
value: 'bar'
}, {
name: 'baz',
value: '...'
});
Upvotes: 4