-2

i got ane object contains array of objects.

Object {
  "isLoadingAPI": true,
  "orgAPIData": Array [
    Object {
      "color1": "#009fe8",
      "color2": "#9c3ab4",
      "color3": "#0bb694",
      "face": true,
      "fingerprint": "true",
      "id": 1234,
      "messageLimit": 10,
      "name": " הטסטים משרד",
      "visible": true,
    },
    Object {
      "color1": "#009fe8",
      "color2": "#9c3ab4",
      "color3": "#0bb694",
      "face": true,
      "fingerprint": "true",
      "id": 3245,
      "messageLimit": 15,
      "name": "טסט",
      "visible": false,
    },
    Object {
      "color1": "#009fe8",
      "color2": "#9c3ab4",
      "color3": "#0bb694",
      "face": false,
      "fingerprint": "false",
      "id": 333,
      "messageLimit": 10,
      "name": " התחבורה משרד ",
      "visible": true,
    },
    Object {
      "color1": "#009fe8",
      "color2": "#9c3ab4",
      "color3": "#0bb694",
      "face": true,
      "fingerprint": "false",
      "id": 9112,
      "messageLimit": 10,
      "name": "פלאריום",
      "visible": true,
    },
    Object {
      "color1": "#009fe8",
      "color2": "#9c3ab4",
      "color3": "#0bb694",
      "face": false,
      "fingerprint": "true",
      "id": 1008,
      "messageLimit": 10,
      "name": "ספיאנס",
      "visible": true,
    },
  ],
}

So here i want to access all "messageLimit" value from above list.

i want to store values in a global variable.

lets say if i am going to console that variable i should get only the values (10,15,10...) like this.

How can i achieve this?

Andy
  • 61,948
  • 13
  • 68
  • 95

2 Answers2

0

You can achive this by Arrays map method.

The arrays map method takes a function as parameter and what ever this function returns will be returned in your results.

So it can be like this.

  var messageLimits = object.orgAPIData.map(oapi=>oapi.messageLimit)
ouflak
  • 2,458
  • 10
  • 44
  • 49
Ejaz Arain
  • 72
  • 4
-1

You can use map function:

const messageLimits = object.orgAPIData.map(apiData => apiData.messageLimit);
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129