arrays - 如何过滤与字符串匹配的数组中的数据?
问题描述
我有一个数据数组,我需要将该数据过滤到 react js 中的一个变量中。
这是我的数组
[{idappcontent: "Com_01", idcontenttype: "0", idclient: "5"},
{idappcontent: "Com_02", idcontenttype: "0", idclient: "5"},
{idappcontent: "Com_03", idcontenttype: "0", idclient: "5"},
{idappcontent: "Review1_Ques_01", idcontenttype: "0", idclient: "5"},
{idappcontent: "Review1_Ques_02", idcontenttype: "0", idclient: "5"},
{idappcontent: "Sign_01", idcontenttype: "0", idclient: "5"},
{idappcontent: "Sign_02", idcontenttype: "0", idclient: "5"},
{idappcontent: "Thank_01", idcontenttype: "0", idclient: "5"},
{idappcontent: "Thank_02", idcontenttype: "0", idclient: "5"}
]
我需要获取包含“idappcontent ==”Sign_“”的数据。如何过滤匹配“Sign_”字符串的数组数据?
解决方案
用这个:
const temp = YOURDATA.filter(item=> item.idappcontent.includes("Sign_"));
欲了解更多信息:
- filter() 方法创建一个新数组,其中包含通过所提供函数实现的测试的所有元素。
- includes() 方法执行区分大小写的搜索,以确定一个字符串是否可以在另一个字符串中找到,并根据需要返回 true 或 false。
推荐阅读
- javascript - 我可以从 server.js 导出变量吗?(或传输环境变量的最佳方式)
- azure - 请验证 QnAMaker 服务中的 Azure 搜索资源是否已启动并正在运行
- c# - 具有类型约束的 C# 重载解决方案没有选择我期望的方法
- javascript - 子函数递归调用方法
- java - 有没有办法将关键侦听器添加到 Jtable 中的特定列?
- reactjs - 如何将 GridList 子组件添加为组件
- bash - 将 exec /bin/bash 添加到脚本以使其行为与 /bin/bash 完全一样?
- r - R函数来确定另一个应用程序是否正在运行
- python - 当我尝试在 pyqt5 中运行语音识别时,程序崩溃了
- javascript - 如何从输入值中查询包含文本字符串的所有文档?