Angular 2 TypeScript how to find element in Array

前端 未结 7 784
抹茶落季
抹茶落季 2021-01-29 21:35

I have a Component and a Service:

Component:

7条回答
  •  被撕碎了的回忆
    2021-01-29 22:05

    from TypeScript you can use native JS array filter() method:

    let filteredElements=array.filter(element => element.field == filterValue);
    

    it returns an array with only matching elements from the original array (0, 1 or more)

    Reference: https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

提交回复
热议问题