Is there a way to remove specific characters from an array in JavaScript?
var wording = ["She", "gives","me", "called", "friend"];
var suffix = ["s", "ed", "ing"];
function removeChars(word) {
for (let i = 0; i < suffix.length; i++) {
if (word.endsWith(suffix[i])) {
return word.slice(0, -suffix[i].length);
}
}
return word;
}
var text = wording.map(removeChars);
console.log(text);
- I need to remove 's' from the word 'gives', but keep 'S' in 'She'.
- I also want to remove 'ed' from 'called'.