代码:
let names= ["Style","List","Raw"];
let results= names.find(x=> x.includes("s");
console.log(results); //
如何从数组名称中获取包含“ s”的名称,目前,我只得到一个元素,但是我需要所有出现。
您必须filter
在这种情况下使用
let names= ["Style","List","Raw"];
let results= names.filter(x => x.includes("s"));
console.log(results); //["List"]
如果您希望它不区分大小写,请使用以下代码,
let names= ["Style","List","Raw"];
let results= names.filter(x => x.toLowerCase().includes("s"));
console.log(results); //["Style", "List"]
为了区分大小写,我们必须将字符串的字符全部转换为小写。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句