【问题标题】:Can I use find method to iterate through the characters of a string?我可以使用 find 方法遍历字符串的字符吗?
【发布时间】:2022-11-11 02:41:13
【问题描述】:

我可以使用 find() 方法搜索字符串而不是数组吗?

像这样: const text = "欢迎"; 常量输出 = text.find(字母=> 单词==="e");

【问题讨论】:

  • 是的,但是您需要先将字符串拆分为字母数组。 const output = text.split("").find(letter => letter === "e");

标签: javascript find


【解决方案1】:

使用String#split

const text = "welcome"; 
const output = text.split('').find(letter => letter === "e");
console.log(output);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-04
    • 2013-06-09
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    • 2014-12-30
    • 2018-05-15
    相关资源
    最近更新 更多