Reputation: 762
I have a string of words (they are separated by new line)
aa
aaa
aaaa
aaaaa
and I want to add it to an array "words"
[1] = aa
[2] = aaa
[3] = aaaa
[4] = aaaaa
how can I do this in ionic 2? I know in java it would look like this
String s = "This is a sample sentence.";
String[] words = s.split("\\s+");
for (int i = 0; i < words.length; i++) {
words[i] = words[i].replaceAll("[^\\w]", "");
}
but can't figure it out in ionic 2.
Upvotes: 0
Views: 1559
Reputation: 24244
In Javascript or Typescript you could do the same with:
const s = "This is a sample sentence.";
const words = s.split(" ");
// displaying the array
for (word of words){
console.log(word);
}
Upvotes: 1