let aim = [
{
"id": "1",
"name": "郑文强",
"gender": "female",
"age": "26",
"idCard": "510322198809163412",
"email": "mtbtwgpuktmu@qq.com",
"address": "安徽合肥",
"createdDate": "2022-07-18 15:50:53"
},
{
"id": "2",
"name": "王琪可乐",
"gender": "female",
"idCard": "12312312313123123",
"age": "19",
"email": "gu@example.com",
"address": "安徽滁州",
"createdDate": "2022-01-16 10:00:00 "
},
{
"id": "3",
"name": "南宫仆射",
"gender": "female",
"age": "26",
"idCard": "12391809248018408124",
"email": "1281023810298@qq.com",
"address": "江湖",
"createdDate": "2022-07-18 11:01:40"
},
{
"id": "4",
"name": "ikun",
"gender": "female",
"age": "19",
"idCard": "7771298100238123",
"email": "123913182@qq.com",
"address": "网络常驻所",
"createdDate": "2022-07-18 15:44:49"
},
{
"id": "5",
"name": "小黑子",
"gender": "male",
"age": "24",
"idCard": "80283042423",
"email": "18723913@qq.com",
"address": "键盘",
"createdDate": "2022-07-18 15:45:18"
},
{
"id": "6",
"name": "igang",
"gender": "male",
"age": "24",
"idCard": "878782787287822",
"email": "287287822@qq.com",
"address": "湖北",
"createdDate": "2022-07-18 15:51:42"
},
{
"id": "7",
"name": "钟圣美",
"gender": "female",
"age": "26",
"idCard": "13012719930708652X",
"email": "287287822@qq.com",
"address": "河北省石家庄市高邑县",
"createdDate": "2022-07-19 15:52:42"
},
{
"id": "8",
"name": "陈莹丽",
"gender": "female",
"age": "22",
"idCard": "230123199602054123",
"email": "32323728782122@qq.com",
"address": "湄潭县哈尔滨市依兰县",
"createdDate": "2022-07-19 14:51:42"
},
{
"id": "9",
"name": "邹洪刚",
"gender": "male",
"age": "20",
"idCard": "520328197502014610",
"email": "287287822@qq.com",
"address": "贵州省遵义市湄潭县",
"createdDate": "2022-07-19 16:51:42"
},
{
"id": "10",
"name": "李无锋",
"gender": "male",
"age": "19",
"idCard": "371423198601191912",
"email": "7880822@qq.com",
"address": "山东省德州市庆云县",
"createdDate": "2022-07-19 14:51:42"
}
]
function filterByName2(aim, name, age,gender) {
let returnData = aim
if(name != '') {
returnData = returnData.filter(item => item.name == name)
if(age != '') {
returnData = returnData.filter(item =>item.age == age)
if(gender != ''){
returnData = returnData.filter(item =>item.gender == gender)
}
}else {
if(gender != ''){
returnData = returnData.filter(item =>item.gender == gender)
}
}
}else {
if(age != '') {
returnData = returnData.filter(item => item.age == age)
if(gender != ''){
returnData = returnData.filter(item =>item.gender == gender)
}
}else {
if(gender != ''){
returnData = returnData.filter(item =>item.gender == gender)
}
}
}
return returnData
}
console.log(filterByName2(aim,'','19',''))
console