-4 html javascript string substring
如果我有“var”,我怎样才能从中得到“e,o,o”?使用子字符串只能获取位置
var str = "Hello world!";
var res = str.substring(1, 4);
Run Code Online (Sandbox Code Playgroud)
小智 5
目前尚不完全清楚您是否只想要元音,或者是否想要除元音之外的所有内容。不管怎样,一个简单的正则表达式就可以得到你需要的字符。
let str = "Hello World";
let res = str.match(/[aeiou]/ig).join("");
console.log(res);
let res2 = str.match(/[^aeiou]/ig).join("");
console.log(res2);
Run Code Online (Sandbox Code Playgroud)
.join("")
如果您想要一个数组,请删除该部分,否则这会给您一个字符串