-1
 "info": [
    {
        "Name": "sda",
        "Icon": null,
        "id": 45
    },
    {
        "Name": "srda",
        "Icon": null,
        "id": 47 
    }]

i have an array of this json body / model class . I need to put only ids into another array in typescript.

Esdras
  • 1
  • 2

1 Answers1

1

You can use map operator for this

var el={
"info": [
    {
        "Name": "sda",
        "Icon": null,
        "id": 45
    },
    {
        "Name": "srda",
        "Icon": null,
        "id": 47 
    }]
}
var result=el.info.map(x=>x.id);
console.log(result);
mr. pc_coder
  • 16,412
  • 3
  • 32
  • 54