JS log object why is showing [object Object]

后端 未结 3 712
天涯浪人
天涯浪人 2020-11-29 09:50

In JS, if I log a string to the console it is not showing properly ?

console.log(uniqueProducts); //
console.log(\"uniqueProducts:\"+uniqueProducts);
         


        
3条回答
  •  清酒与你
    2020-11-29 10:21

    You are trying to concatenate an object with a string. You can fix it one of two ways:

    1. Remove + from the log call

      console.log("uniqueProducts:", uniqueProducts );

    2. You can use JSON.stringify to print the object as JSON:

      console.log("uniqueProducts:", JSON.stringify(uniqueProducts));

提交回复
热议问题