如何在数组中删除单词的最后一个符号



我的数组带有以 *符号结尾的单词,我需要删除此符号。如果我的代码创建数组是:

我该怎么办

我试图使用参考来进行,但我的尝试不起作用。

let tempArray = this.state.textInput.split(" "); // convert string into array
let filterArray = tempArray.filter(word => word.endsWith("*"));

let tempArray = ["asds*","dseas*","adas"];
let newArray = tempArray.map((word)=>{
if(word.endsWith("*")){
    word = word.slice(0, word.length-1);
}
return word;})
console.log(newArray);

尝试以下:

tempArray.forEach(function(part, index, theArray) {
  theArray[index] =  theArray[index].replace("*","");
});

最新更新