I am just starting to learn JS and I'm puzzled by a situation. Let's consider the following code snippet:
var ids = [10,20,30];
var types= ['PIZZA','HAMBURGER','AVOCADO'];
var payload=[];
for(let i = 0; i <= ids.length; i++){
var id= ids[i];
var type= types[i];
var couple= {"id":id ,"type":type};
console.log(couple);
payload.push(couple);}
console.log('result is ' + payload);
The output shows: [object Object],[object Object],[object Object],[object Object]
My expectation was something like :
{ "id" : 10, "type" : "PIZZA" },
{ "id" : 20, "type" : "HAMBURGER" },
{ "id" : 30, "type" : "AVOCADO" }
Why does {} + {} result in "Object object][Object object"? Could you please provide some insight on how to prevent this in JS?
Thank you for your time and looking forward to some helpful feedback! Wishing you a wonderful day!