我正在学习 Javascript,并且正在制作一个简单的用户验证对象。我需要一个函数,该函数将仅将“isVerified”设置为 true 的用户记录到 console.log。
我尝试了很多方法,包括循环和 if 语句。下面的函数名称是“showVerified”。
var person = {
info: [],
displayPerson: function() {
console.log('People', this.info);
},
addPerson: function(age, firstName, lastName) {
this.info.push({
age: age,
firstName: firstName,
lastName: lastName,
isVerified: false
});
this.displayPerson();
},
deletePerson: function(position) {
this.info.splice(position, 1);
this.displayPerson();
},
verifyPerson: function(position) {
this.info[position].isVerified = true;
this.info[position].firstName = this.info[position].firstName.toUpperCase();
this.displayPerson();
},
showVerified: function() {
for (var key in this.info) {
if (this.info.isVerified = true) {
console.log(this.info.isVerified[key]);
}
}
}
}
在我的 person 对象上运行 showVerified 时,我想要发生的是,它只打印出任何经过验证的人的年龄、名字和姓氏。
弑天下
饮歌长啸
相关分类