[英]How to access values to use values from nested object in JavaScript?
我被困住了我使用金融 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
不要忘記添加它包含的內容,在這種情況下我猜是companyData
companyData.data.profile.price
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.