【发布时间】:2018-06-11 21:30:09
【问题描述】:
我有运行猫鼬并成功返回以下结果的代码。
为什么我不能执行以下操作并从我的对象中获取值?
Object.keys(result).forEach(function(record){
console.log("The value of result[record]: ", result[record]);
})
如何遍历此对象以获取不同的键来获取列表和对象中的值?
我正在使用普通的 javascript。但我不介意一些较新的 ES 选项。
{ owner: { fullName: 'xxx', userName: 'xxx' },
members: [ { userName: 'xxx', fullName: 'xxx', position: '' } ],
admins: [ 'xxx','ashg' ],
_id: 5a482302a469a068edc004e3,
type: 'xxxx',
name: 'xxxx xxxx',
descrip: 'xxxx',
startDate: '2018-01-01',
endDate: ''
}
这是我想要复制的一个更简单的示例,它完全按预期工作:
var o={a:1,b:2,c:3};
var val;
Object.keys(o).forEach(function(key) {
val = o[key];
console.log(val);
});
Output: 1,2,3
【问题讨论】:
-
console.log("result[record]: ", record );的输出是什么
标签: javascript arrays object mongoose