<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动态改变if中的判断内容</title>
</head>
<body>
<script>
let list = [
{
name: '孙悟空',
phone: '13896965655'
},
{
name: '爱米莉娅',
phone: '12589633654'
},
{
name: '雷姆',
phone: '13589633684'
},
{
name: '孙二娘',
phone: '13564236966'
}
]
//其中filterObj中的元素会动态改变,有没有一种方法让filter中if判断的内容也动态的改变
// 1. let filterObj = {
// name: '孙',
// }
// let newlist = []
// list.filter((item) => {
// if ((item.name.indexOf(filterObj.name) !== -1)) {
// newlist.push(item);
// }
// });
// console.log(newlist)
// 2. let filterObj = {
// phone:'1'
// }
// let newlist = []
// list.filter((item) => {
// if ((item.phone.indexOf(filterObj.phone) !== -1)) {
// newlist.push(item);
// }
// });
// console.log(newlist)
//3.
// let filterObj = {
// name: '孙',
// phone: '1'
// }
// let newlist = []
// list.filter((item) => {
// if ((item.name.indexOf(filterObj.name) !== -1) && (item.phone.indexOf(filterObj.phone) !== -1)) {
// newlist.push(item);
// }
// });
// console.log(newlist)
//以上合成一块代码如何编写
</script>
</body>
</html>