如何过滤数组中与字符串匹配的数据?

Sid*_*ath 1 arrays sorting reactjs

我有一个数据数组,我需要将这些数据过滤到 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"}
]
Run Code Online (Sandbox Code Playgroud)

我需要获取包含“idappcontent ==”Sign_“”的数据。如何过滤与“Sign_”字符串匹配的数组数据?

Abb*_*hsn 5

用这个:

const temp = YOURDATA.filter(item=> item.idappcontent.includes("Sign_"));
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息:

  1. filter() 方法创建一个新数组,其中包含通过所提供函数实现的测试的所有元素。
  2. include() 方法执行区分大小写的搜索以确定是否可以在另一个字符串中找到一个字符串,并根据需要返回 true 或 false。