【发布时间】:2022-11-11 02:41:13
【问题描述】:
我可以使用 find() 方法搜索字符串而不是数组吗?
像这样: const text = "欢迎"; 常量输出 = text.find(字母=> 单词==="e");
【问题讨论】:
-
是的,但是您需要先将字符串拆分为字母数组。
const output = text.split("").find(letter => letter === "e");
标签: javascript find
我可以使用 find() 方法搜索字符串而不是数组吗?
像这样: const text = "欢迎"; 常量输出 = text.find(字母=> 单词==="e");
【问题讨论】:
const output = text.split("").find(letter => letter === "e");
标签: javascript find
使用String#split:
const text = "welcome";
const output = text.split('').find(letter => letter === "e");
console.log(output);
【讨论】: