gatsby-source-custom-api icon indicating copy to clipboard operation
gatsby-source-custom-api copied to clipboard

I want to get only first 3 elements from an array. Is that possible ?

Open ShuvoHabib opened this issue 4 years ago • 1 comments

Let's say we're getting an array of 5 items from the API. Can we get only 3 items, not all the 5 items?

{
  "data": {
    "finance": {
      "data": [
        {
          "id": "590522000022443198",
          "City": "Melaka"
        },
        {
          "id": "590522000025688127",
          "City": "Limassol"
        },
        {
          "id": "590522000037762639",
          "City": "Cyberjaya"
        },
        {
          "id": "590522000037762487",
          "City": "Labuan"
        },
        {
          "id": "590522000022432183",
          "City": "Ipoh"
        }
      ]
    }
  },
}

ShuvoHabib avatar Mar 08 '22 12:03 ShuvoHabib

If you are talking about graphql then you can add limit in your query and limit it to n number of elements in the results.

MuhammadHadiofficial avatar Apr 22 '22 01:04 MuhammadHadiofficial