Can anyone assist me with a task I'm working on? I'm trying to write a function that checks the letters of a string. I attempted to use both a for
loop and a foreach
loop, but I couldn't get it to work properly :(
let input = this.tagsForm.controls["tagInput"].value;
let lettersArray: [];
for (var i = 0; i < input.length; i++) {
if(input.charAt(i) !== "," || input.charAt(i) !== ";" || input.charAt(i) !== "/") {
lettersArray = input.charAt(i);
alert(lettersArray);
} else {
alert('error');
}
}
}
I need to iterate through each letter of the string obtained from a form control in Angular and check if it is a delimiter. If it is, I need to extract everything before that position and store it in an array.
The delimiters can be a comma, semicolon, or a newline. Any assistance is greatly appreciated.