且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular 2 TypeScript如何在数组中查找元素

更新时间:2022-11-13 22:37:51

您需要使用方法

You need to use method Array.filter:

this.persons =  this.personService.getPersons().filter(x => x.id == this.personId)[0];

Array.find

this.persons =  this.personService.getPersons().find(x => x.id == this.personId);