Search code examples
angularrxjs-pipeable-operators

how to properly filter an array in angular


I have a service ice that pulls an array from the back-end, I need to get a single item from the array based on the ID, how do I do this in Angular?

enter image description here

I'm looking for how to do it specifically with angulars pipeable operators. Filter tends to just stop everything from working without throwing errors if not done correctly. I can get the the row info but I cant target the properties i get "Cannot read property 'id' of undefined"


Solution

  • I need to get a single item from the array based on the ID

    try with Array.find()

    let data = yourArray.find(x => x.id == "en-gb");
    

    or try with array().filter().shift()

    Please go through this below discussion

    Difference between find() and filter().shift() on javascript