jq 去除obj或数组中的空值
2022-04-01 15:38:30 来源:admin 点击:588
1、jQuery代码示例如下
//定义一个带有空值的数组
var userIdArr= ["1", "2", "5", "8", " ","12"];
//去掉数组中的空值
var userIds = this.userIdArr.filter(s => $.trim(s).length > 0);
//输出结果
console.log(userIds);
2、输出结果如下
结果:["1", "2", "5","8","12"]