对于中的数组,有任何方法可以使用类似于的过滤器吗?我只能对数组使用filter函数,但它需要匹配确切的过滤器才能获取元素。
this.myArray= this.myArray2.filter(myClass => myClass.name == value);我想要的是,如果value == 'mar',它将返回数组中的所有元素,其中包含'mar'的名称(例如,Mark、Romar、Smarts等)。
发布于 2018-01-18 14:43:23
使用string方法includes()
this.myArray= this.myArray2.filter(element => element.name.includes(value));请参阅下面的链接来阅读有关includes()方法的内容:Objects/String/includes
https://stackoverflow.com/questions/48323835
复制相似问题