'How can access a object property value from Objects contains array of objects in Js [duplicate]

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?



Solution 1:[1]

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)

Solution 2:[2]

You can use map function:

const messageLimits = object.orgAPIData.map(apiData => apiData.messageLimit);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak
Solution 2 Kai - Kazuya Ito