检查字符串数组是否在javascript中包含子字符串

编程入门 行业动态 更新时间:2024-10-15 16:26:18
本文介绍了检查字符串数组是否在javascript中包含子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我对这项任务有些困惑 我有一个像这样的数组: 数组= ["123","456",#123"] 我想找到包含#的元素.我使用了array.includes("#")和array.indexOf("#"),但是没有用 有什么想法吗?

i'm a little bit confused with this task I have an array like this: array = ["123", "456", "#123"] i want to find the element which contains the #. I used array.includes("#") and array.indexOf("#") but it didn't work Any ideas??

推荐答案

因为include会将'#'与每个数组元素进行比较.

Because includes will compare '#' with each array element.

让我们尝试使用一些或查找如果要查找是否要精确获取元素

Let's try with some or find if you want to find if you want to get exactly element

var array = ["123", "456", "#123"]; var el = array.find(a =>a.includes("#")); console.log(el)

更多推荐

检查字符串数组是否在javascript中包含子字符串

本文发布于:2023-11-29 16:10:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   数组   javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!