I have two objects such as:
{ Count: 1,
Items:
[ { foo: [Object],
name: [Object],
bar: [Object],
baz: [Object],
qux: [Object] } ] }
and
{ Count: 0, Items: [] }
I need to combine them and return one JSON object. However, when I try this, I get
"[object Object][object Object]"
code:
function returnResponse(obj1, obj2) {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
var returnResult = obj1 + obj2
res.send(JSON.stringify(returnResult, undefined, 2));
res.end();
}
How do I get all the objects to appear correctly in the browser?
+performance string concatenation and the default string representation of an object is[object Object].obj1andobj2are objects, not JSON objects. There is no such thing as a "JSON object".{}. Here is another:{ combined: true }. There is near-infinite "single objects". These are obviously not what you want, but it is much less obvious to us what you do want. Please edit your question and explicitly write out what you expect the result of the "combination" of your two example objects is.