//过滤请求参数中的空字符串,null和undefined值
const searchData = {
job: 'teacher',
name: '',
age: null,
sex: null,
hobby: undefined,
under_take_count: {
target_type: 0,
target_count_from: '',
target_count_end: '',
},
};
function handleData(data) {
const keys = Object.keys(data);
if (keys.length > 0) {
keys.forEach(currentKey => {
const currentVal = data[currentKey];
debugger;
if (!Array.isArray(currentVal) &&(currentVal instanceof Object) ) {
data[currentKey]= handleData(currentVal);
} else {
if (['', null, undefined].includes(currentVal)) {
delete data[currentKey]
}
}
})
}
return data;
};
console.log(handleData(searchData));
console