Merge JavaScript objects
javascript, string-concatenation
Solution
This should work.
var array = []
array.push(yourObject);
this will put your object into an array, which should be used if you were putting of a collection of the same object into one.
to merge different values into one object:
function makeObject(){
var obj = {};
obj['info'] = somevalue; //arguments [0] maybe
obj['power'] = somevalue;
obj['accuracy'] = somevalue;
obj['type'] = somevalue;
obj['category'] = somevalue;
obj['pp_min'] = somevalue;
obj['pp_max'] = somevalue;
return obj;
}
Here is a link also describing passing arguments like array into a function in JavaScript which could be useful in creating the merged object.
http://www.cherny.com/webdev/60/javascript-function-arguments-default-values-passing-objects-and-overloading
Problem
I've read another similiar question on SO but there wasn't a clear answer at that question. I got some JavaScript objects that look like this: ``` var moveJSON = { 'name' : move[0].innerHTML, 'info' : move[1].innerHTML, 'power' : move[2].innerHTML, 'accuracy' : move[3].innerHTML, 'type' : move[4].innerHTML, 'category' : move[5].innerHTML, 'pp_min' : move[6].innerHTML, 'pp_max' : move[7].innerHTML } ``` I need to merge them into one object, that will be send to PHP via AJAX. But first: what's the best way to merge them into a single object (array)?