let teacher = {
name:'苍老师',
age:18,
height:155,
weight:90,
print:function(){
console.log(this.name);
},
boyFriends:[
{id:1,name:'一'},
{id:2,name:'二'},
{id:3,name:'三'},
{id:4,name:'四'}
],
husband:{
name : '张三',
age : 60,
},
};
console.log(teacher.boyFriends)
// 基本
//for(var i = 0; i < teacher.boyFriends.length; i++){
// if(teacher.boyFriends[i].id !== 3 ){
// teacher.//boyFriends.splice(i,(teacher.boyFriends.length -1));
// }
//}
//进阶
// for(let i=teacher.boyFriends.length-1; i>=0; i--){
// if(teacher.boyFriends[i].id !== 3){
// teacher.boyFriends.splice(i,1);
// }
// }
//便利方法
teacher.boyFriends = teacher.boyFriends.filter(({ id }) => id === 3);
//定点删除
//teacher.boyFriends.splice(teacher.boyFriends.findIndex(item => item.id != 3), 1)
console.log(teacher.boyFriends)
console