如何在数组中使用过滤器,类似于 SQL for AngularJS 中的"Like"子句



有没有办法在 Angular5 中对数组使用 LIKE 过滤器?我只能对数组使用过滤器函数,但它需要匹配确切的过滤器才能获取元素。

this.myArray= this.myArray2.filter(myClass => myClass.name == value);

我想要的是,如果value == 'mar',它将返回数组的所有元素,其中包含带有'mar'的名称(例如 Mark、Romar、Smarts 等(

使用字符串方法includes()

this.myArray= this.myArray2.filter(element => element.name.includes(value));

请参阅以下链接以了解有关includes()方法的信息:https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/String/includes

最新更新