TypeScript中使用数组的filter方法

const arr: string[] = ['pom', '皮蛋编程', '非常厉害', '太棒了'];

const filteredArr: string[] = arr.filter((str: string) => {
  return str.includes('编程');
});

console.log(filteredArr); // ["皮蛋编程"]
 
arr是数组

includes():包含

只返回匹配对象结果
posted @ 2023-08-09 12:51  3939!  阅读(256)  评论(0编辑  收藏  举报