例如:this.monitorInfo.keywordList = ["张三","" ,"" ,"李四","","王麻子"];
let arr =[]
for(let i =0;i<=this.monitorInfo.keywordList.length-1;i++){
if(this.monitorInfo.keywordList[i].trim() != "" ){
arr.push(this.monitorInfo.keywordList[i])
}
}
this.monitorInfo.keywordList = arr ;
输出结果: this.monitorInfo.keywordList = ["张三","李四","王麻子"];
删除的数组的某一项
splice(index,len,[item]) 注释:该方法会改变原始数组。
splice有3个参数,它也可以用来替换/删除/添加数组内某一个或者几个值
index:数组开始下标 len: 替换/删除的长度 item:替换的值,删除操作的话 item为空
如:arr = ['a','b','c','d']
删除
1 2 3 4 5 6 7 8 9 10 11 12 |
|
替换
1 2 3 4 5 6 7 8 9 10 11 |
|
添加 ---- len设置为0,item为添加的值
1 2 3 4 |
|