Angular 2 TypeScript how to find element in Array

前端 未结 7 782
抹茶落季
抹茶落季 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

    0 讨论(0)
提交回复
热议问题