Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
74
rated 0 times [  76] [ 2]  / answers: 1 / hits: 5991  / 4 Years ago, fri, october 23, 2020, 12:00:00

If i have 'var' how can i get "e,o,o" out of it ?
With substring you can only get the position


var str = "Hello world!";
var res = str.substring(1, 4);

More From » html

 Answers
11

It's not entirely clear if you only want the vowels or if you want all except the vowels. Either way, a simple regular expression can get the characters you need.




let str = Hello World;

let res = str.match(/[aeiou]/ig).join();
console.log(res);

let res2 = str.match(/[^aeiou]/ig).join();
console.log(res2);




Remove the .join("") part if you want an array, otherwise this gives you a string


[#2433] Monday, October 19, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristab

Total Points: 735
Total Questions: 106
Total Answers: 96

Location: Grenada
Member since Sun, Dec 20, 2020
3 Years ago
tristab questions
;