我有一个代码段,试图从对象中删除某些属性。
const actionSchema = new mongoose.Schema({}, {strict: false});
const userSchema = new mongoose.Schema({
undoActions:[actionSchema]
redoActions:[actionSchema]
});
User.findById(userId)
.exec()
.then(user => {
user.redoActions.push(user.undoActions[user.undoActions.length-1])
user.undoActions.splice(user.undoActions.length-1, 1)
// or use user.undoActions.pop()
return user.save();
})
.then(user => console.log(user))
.catch(err => console.log(err));
当我在let users = [{name: "a", prop1: 1, prop2: 2},{name: "b", prop1: 2, prop2: 2}, {name: "c", prop1: 3, prop2: 2}];
console.log("before deleting property", users);
for (var i = 0; i < users.length; i++) {
delete users[i]['name'];
}
console.log("after deleting property", users);
中运行此代码时,输出为:
NodeJS
但是,当我在浏览器中执行相同的代码(Google Chrome版本73.0.3683.103(正式版本)(64位)-Mac OS)时,输出更改(两个日志消息中的属性均被删除):< / p>
相关的jsFiddle:https://jsfiddle.net/abhas9/f0erjhv2/12/
但是,如果我将日志消息更改为:
before deleting property [ { name: 'a', prop1: 1, prop2: 2 },
{ name: 'b', prop1: 2, prop2: 2 },
{ name: 'c', prop1: 3, prop2: 2 } ]
after deleting property [ { prop1: 1, prop2: 2 },
{ prop1: 2, prop2: 2 },
{ prop1: 3, prop2: 2 } ]
我得到了预期的输出。
我想念什么吗?这是浏览器在开发人员工具中优化日志语句的方式吗?如果是,是否有任何相关规范?