How can i remove an element that contains a specific letter from an array
function longest7SegmentWord(arr) {
///forbidden characters
var dellValue = ["k", "m", "v", "w" ,"x"]
for (var i=0; i<arr.length; i++) {
for(var j=0; j<dellValue.length; j++){
if (arr[i].indexOf(dellValue[j]) !==-1){
console.log(arr[i])
}
}
}
}
longest7SegmentWord(["knighthood", "parental", "fridge", "clingfilm", "k", "m", "v", "w"])
For example in this function the output should be
"parental", "fridge"
I know that te problem is happening because the loop of "dellValue" keep returning the others deleted value, for example :
arr[i].indexOf(dellValue[0])
return every element without the "k" , but after when dellValue[1] is hit, return everything despite of "m" ecc... is there other solutions, even using RegEx, such us search() / filter ()