Javascript 输出结果时获取[object]
我不知道为什么会得到Javascript 输出结果时获取[object],javascript,Javascript,我不知道为什么会得到[object object]。我希望能够处理从中产生的数据。如果你有任何想法,我将不胜感激。谢谢大家! const response = await axios.get(url); const { data } = response; const result = data.map(item => ({ date: Date.parse(item.date), open: item.open, high: item
[object object]
。我希望能够处理从中产生的数据。如果你有任何想法,我将不胜感激。谢谢大家!
const response = await axios.get(url);
const { data } = response;
const result = data.map(item => ({
date: Date.parse(item.date),
open: item.open,
high: item.high,
low: item.low,
close: item.close,
volume: item.volume,
}));
console.log(`fetchWebApiStock result data: ${result}`);
编辑:
console.log('fetchWebApiStock result data:', result);
请用这个
console.log(`result data: ${JSON.stringify(item)}`)
请用这个
console.log(`result data: ${JSON.stringify(item)}`)
您只需要对对象使用
JSON.stringify()
。当前,您的对象正在与字符串值连接,这将使整个结果成为字符串,并对其进行字符串化,然后将对象显示为字符串
const result=()=>{
返回{
物业:12
};
};
var res=结果();
console.log('result data:'+JSON.stringify(res))
您只需要对对象使用JSON.stringify()。当前,您的对象正在与字符串值连接,这将使整个结果成为字符串,并对其进行字符串化,然后将对象显示为字符串
const result=()=>{
返回{
物业:12
};
};
var res=结果();
console.log('result data:'+JSON.stringify(res))
由于字符串与对象关联而发生
我更喜欢:
`console.log('result data: ', item)`
这也有助于我在浏览器控制台上展开、折叠对象并对其进行良好的分析。这是因为字符串与对象相连
我更喜欢:
`console.log('result data: ', item)`
这有助于我在浏览器控制台上展开、折叠对象并对其进行良好的分析。您可能只想严格地item
:console.log(`result data:${JSON.stringify(item)}`)
您可能只想严格地item
:console.log(`result data:${JSON.stringify(item)}`)
@JohnJohn我不明白,你的意思是你把对象和“未定义”都打印在控制台的两行中吗?我编辑了我的问题。我不确定哪里弄错了,但由于某种原因,我没有得到结果。@JohnJohn这可能是因为for循环不返回任何东西。也许可以将结果推送到循环中的数组中,然后将数组返回到循环外。除此之外,你需要把内部函数变成一个生命,或者称之为生命manually@JohnJohn我不明白,你的意思是你把对象和“未定义”都打印在控制台的两行中吗?我编辑了我的问题。我不确定哪里弄错了,但由于某种原因,我没有得到结果。@JohnJohn这可能是因为for循环不返回任何东西。也许可以将结果推送到循环中的数组中,然后将数组返回到循环外。除此之外,您需要使内部函数成为一个生命,或者手动调用它