Javascript 在具有console.log的对象数组中无法访问带引号的属性
假设我在JS文件中有此节点代码:Javascript 在具有console.log的对象数组中无法访问带引号的属性,javascript,node.js,Javascript,Node.js,假设我在JS文件中有此节点代码: const fs = require('fs') const getStream = require('get-stream').array const csvParse = require('csv-parser') async function parse() { let geoRows = await getStream( fs.createReadStream('./result.csv') .pipe(csvParse())
const fs = require('fs')
const getStream = require('get-stream').array
const csvParse = require('csv-parser')
async function parse() {
let geoRows = await getStream(
fs.createReadStream('./result.csv')
.pipe(csvParse())
)
console.log(geoRows[0])
}
它显示(在控制台上):
有点奇怪:id
在引号中,我不知道为什么。但我真正的问题是这个id
是无法访问的:
console.log(geoRows[0].id, geoRows[0]['id'], geoRows[0]["'id'"])
它显示(在控制台上):
所以我的(双重)问题是:为什么?我如何访问该id
属性?
旁注:唯一有效的方法是
Object.values(geoRows[0])[0]
但它很难看。你能验证两件事吗,getRows[0]返回数组或对象,以及你是否得到实际的对象或JSON。您可能需要解析该对象。该输出不是正确的json输出,因此很难理解为什么您的代码不工作。无法在此处复制,您能想出一个可复制的示例吗?console.log(json.stringify(geoRows[0]))
说什么?您确定这与您在console中看到的完全相同吗?它的语法无效。您有额外的}
console.log(geoRows[0].id, geoRows[0]['id'], geoRows[0]["'id'"])
undefined undefined undefined