【亡羊补牢】JS灵魂之问 第3期 查找当前字符 e 在字符串中的所有位置

JavaScript介绍

主要是了解 JavaScriptECMAScript 关系。ECMAScript是一种语言标准,而 JavaScript 是对 ECMAScript 的一种实现。

如何查找当前字符的所有位置

/* 查找当前字符 e 在字符串中的所有位置 */
let str = 'Learning is like sailing against the current'
let pos = str.indexOf('e')
let arr = []
while(pos !== -1){
  arr.push(pos)
  pos = str.indexOf('e',pos+1)
}
console.log(arr)

最后

文章产出不易,还望各位小伙伴们支持一波!

往期精选:

小狮子前端の笔记仓库

访问超逸の博客,方便小伙伴阅读玩耍~

学如逆水行舟,不进则退

猜你喜欢

转载自blog.csdn.net/weixin_42429718/article/details/108437790