input string: "abc def, ghi jkl, mnopq"
Desired Output Arrays: ["abc","def"] ["ghi", "jkl"] ["mnopq"]
The input can be any combination of phrases separated by spaces, those phrases are then separated by commas. I need to make a new array for each input string which is followed by a comma. When those arrays are created they have to be split by " ".
Below is the code to split the string into array values using a comma as a separator:
str = "abc def, ghi jkl, mnopq";
const commaSeparatedArray = this.str.split(',').filter(s => s.slice(-1) !== ' ');
console.log(commaSeparatedArray);
Not sure if the next step to take here is a for or while loop for such actions or a javascript prototype?
Link to stackblitz: https://stackblitz.com/edit/angular-ivy-vbdae5?file=src%2Fapp%2Fapp.component.ts