Angular 2 TypeScript how to find element in Array

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

I have a Component and a Service:

Component:

7条回答
  •  [愿得一人]
    2021-01-29 21:49

    Assume I have below array:

    Skins[
        {Id: 1, Name: "oily skin"}, 
        {Id: 2, Name: "dry skin"}
    ];
    

    If we want to get item with Id = 1 and Name = "oily skin", We'll try as below:

    var skinName = skins.find(x=>x.Id == "1").Name;
    

    The result will return the skinName is "Oily skin".

提交回复
热议问题