如下demo,可以进行去重操作,可以参考一下:interface Item{ id:number; name:string } function uniqueBy(val:Array<Item>){ const newarr=val.filter((item,index,self)=>{ return (index===self.findIndex((t)=>t.id===item.id)) }) console.log(JSON.stringify(newarr)) } @Entry @Component struct Index{ @State arr: Array<Item> = [ {id:1,name:'banana'}, {id:2,name:'organge'}, {id:3,name:'banana2'}, {id:3,name:'banana2'}, {id:3,name:'banana2'}, {id:4,name:'banana'}, ] onPageShow(): void { uniqueBy(this.arr) } build() { Column(){ Text('测试页面') } } }
如下demo,可以进行去重操作,可以参考一下: