Algolia response come in an array format

hi everyone, am trying to paginate result gotten from algolia response with the code below

index.search('l', {
  attributesToRetrieve: ['pName'],
  hitsPerPage: 9
}).then(({
    hits
  }) => {
  var respondString = JSON.stringify(hits);
  console.log('response equals  == ' +respondString);
}).catch(function (e) {});

when i log the response it gave me this json in an array format -->>>

[
    {
      "pName": "laptop10",
      "objectID": "3770345000",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop10",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    },
    {
      "pName": "laptop3",
      "objectID": "3770344000",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop3",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    },
    {
      "pName": "laptop4",
      "objectID": "37703240",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop4",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    }
  ]

but am expecting a result like this for me to paginate my data

{
  "hits": [
    {
      "pName": "laptop10",
      "objectID": "3770345000",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop10",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    },
    {
      "pName": "laptop3",
      "objectID": "3770344000",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop3",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    },
    {
      "pName": "laptop4",
      "objectID": "37703240",
      "_highlightResult": {
        "pName": {
          "value": "<em>l<\/em>aptop4",
          "matchLevel": "full",
          "fullyHighlighted": false,
          "matchedWords": [
            "l"
          ]
        }
      }
    }
  ],
  "nbHits": 10,
  "page": 0,
  "nbPages": 1,
  "hitsPerPage": 15,
  "exhaustiveNbHits": true,
  "query": "l",
  "params": "attributesToRetrieve=%5B%22pName%22%5D&hitsPerPage=15&query=l",
  "processingTimeMS": 1
 
}

please can anyone help me out

You’re destructuring hits from the response in your callbabk function argument. I think the full response is what you expect.

index.search('l', {
  attributesToRetrieve: ['pName'],
  hitsPerPage: 9
}).then((response) => {  // <------ here, no { hits }
  console.log(response)
}).catch(function (e) {});