Geo*_*Geo 1 javascript json for-loop properties object
我有一个for loop在JSON对象上运行并返回控制台中的属性.我想要做的是返回控制台中该属性的值.
这是代码
for (var i in response) {
console.log(i); //return the property to the console
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到response.i财产的名称而不只是财产的名称?
请尝试以下方法:
console.log(response[i]);
Run Code Online (Sandbox Code Playgroud)
您正在迭代抛出对象,但它i是集合中属性的编号,而不是属性值.