You need to use JSON.stringify()
for the object only.(您只需要对对象使用JSON.stringify()
。)
Currently, your object is concatenating with the string value which will make the entire result as string and stringifying it will then show the object as string.(当前,您的对象正在与字符串值连接,该值将使整个结果成为字符串,然后对其进行字符串化,然后将该对象显示为字符串。)
const result = () => { return { someProperty: 12 }; }; var res = result(); console.log('result data:' + JSON.stringify(res))
Even if you do not use JSON.stringify()
the way you did, it implicitly convert the object to string as shown below.(即使您不像JSON.stringify()
那样使用JSON.stringify()
,它JSON.stringify()
隐式将对象转换为字符串,如下所示。) That is why your code do not work:(这就是为什么您的代码不起作用的原因:)
const result = () => { return { someProperty: 12 }; }; var res = result(); console.log(`result data: (${res})`);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…