配列内の空の文字列の除去
4037 ワード
配列内の空の文字列の除去
this.historyKeywords = ["1","","","3","2",""];
console.log("this.historyKeywords",this.historyKeywords)// ["1","","","3","2",""]
for (var i = 0; i < this.historyKeywords.length; i++) {
if (
this.historyKeywords[i] == "" ||
this.historyKeywords[i] == null ||
typeof this.historyKeywords[i] == undefined
) {
this.historyKeywords.splice(i, 1);
i = i - 1;
}
}
console.log("this.historyKeywords",this.historyKeywords)// ["1","3","2"]