gpt4 book ai didi

javascript - 如何访问值以使用 JavaScript 中嵌套对象的值?

转载 作者:行者123 更新时间:2023-12-04 10:49:53 24 4
gpt4 key购买 nike

我被困住了我使用金融 API,但是我无法理解如何让该信息呈现在页面上。我需要在配置文件和 vol Avg 中确定价格。请帮忙。

这就是我使用的,我可以console log data.body它返回嵌套对象。

data {
symbol: 'AAPL',
profile: {
price: 291.45,
beta: '1.139593',
volAvg: '36724977',
mktCap: '1345844630130.00',
lastDiv: '2.92',
range: '142-233.47',
changes: -0.75,
changesPercentage: '(-0.25%)',
companyName: 'Apple Inc.',
exchange: 'Nasdaq Global Select',
industry: 'Computer Hardware',
website: 'http://www.apple.com',
description: 'Apple Inc is designs, manufactures and markets mobile communication and media devices and personal computers, and sells a variety of related software, services, accessories, networking solutions and third-party digital content and applications.',
ceo: 'Timothy D. Cook',
sector: 'Technology',
image: 'https://financialmodelingprep.com/images-New-jpg/AAPL.jpg'
}
}



app.post('/search', (req, res) => {
superagent.get(`https://financialmodelingprep.com/api/v3/company/profile/AAPL`).then(data => {

const companyData = data.body.map(company => new Company(company));
// console.log(data, companyData);
res.render('/search', { companyData });
}).catch(error => {
res.render('error', { error });
});
});

最佳答案

您可以通过 data.profile.price 访问价格和 avgvol 与 data.profile.volAvg
不要忘记添加它所包含的内容,在这种情况下,我猜是 companyDatacompanyData.data.profile.price

关于javascript - 如何访问值以使用 JavaScript 中嵌套对象的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59537422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com