我正在學習 Javascript,并且正在制作一個簡單的用戶驗證對象。我需要一個函數(shù),該函數(shù)將僅將“isVerified”設置為 true 的用戶記錄到 console.log。我嘗試了很多方法,包括循環(huán)和 if 語句。下面的函數(shù)名稱是“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 時,我想要發(fā)生的是,它只打印出任何經(jīng)過驗證的人的年齡、名字和姓氏。
如何僅打印出為真的對象值?
守著一只汪
2021-10-14 16:39:59