Javascript 如何在';对于in';环

Javascript 如何在';对于in';环,javascript,api,fetch,Javascript,Api,Fetch,fetch('https://api.covid19india.org/state_district_wise.json') .then(Response=>Response.json()) 。然后(数据=>{ 用于(数据中的常量属性){ 控制台日志(道具) console.log(prop.statecode)//未定义的原因,我如何访问它? } })使用对象条目,并以键和值清晰的方式销毁对象 fetch('https://api.covid19india.org/state_distric

fetch('https://api.covid19india.org/state_district_wise.json')
.then(Response=>Response.json())
。然后(数据=>{
用于(数据中的常量属性){
控制台日志(道具)
console.log(prop.statecode)//未定义的原因,我如何访问它?
}

})
使用对象条目,并以
清晰的方式销毁对象

fetch('https://api.covid19india.org/state_district_wise.json')
.then(Response=>Response.json())
。然后(数据=>{
Object.entries(data).forEach(([key,value])=>{
console.log(value.statecode)
})

})
使用对象条目,并以
清晰的方式销毁对象

fetch('https://api.covid19india.org/state_district_wise.json')
.then(Response=>Response.json())
。然后(数据=>{
Object.entries(data).forEach(([key,value])=>{
console.log(value.statecode)
})

})
您应该使用将其转换为键值对,并使用迭代结果

fetch(“https://api.covid19india.org/state_district_wise.json")
.then((Response)=>Response.json())
。然后((数据)=>{
//console.log(数据)
for(对象项(数据)的常量[键,值]){
console.log(value.statecode)
}

})
您应该使用将其转换为键值对,并使用迭代结果

fetch(“https://api.covid19india.org/state_district_wise.json")
.then((Response)=>Response.json())
。然后((数据)=>{
//console.log(数据)
for(对象项(数据)的常量[键,值]){
console.log(value.statecode)
}

})
prop
在这里是一个字符串

您需要使用
prop
作为数据中的键来获取对象并从中访问
statecode

fetch('https://api.covid19india.org/state_district_wise.json')
.then(Response=>Response.json())
。然后(数据=>{
用于(数据中的常量属性){
控制台日志(道具)
console.log(data[prop].statecode)//未定义原因?,我如何访问它?
}

})
prop
在这里是一个字符串

您需要使用
prop
作为数据中的键来获取对象并从中访问
statecode

fetch('https://api.covid19india.org/state_district_wise.json')
.then(Response=>Response.json())
。然后(数据=>{
用于(数据中的常量属性){
控制台日志(道具)
console.log(data[prop].statecode)//未定义原因?,我如何访问它?
}

})
prop
是关键,而不是对象。您可以使用
data[prop]
来获取值/对象^<代码>道具是关键,而不是对象。您可以使用
data[prop]
来获取值/对象^?