Array become object when the array length is greater than 21 when try to convert querystring to object

35 Views Asked by At

I want to convert the query string to object in react using qs package

here is my code

import qs from "qs";

export default function App() {
  const arr1 = {
    value: [
      "guava",
      "fig",
      "cherry",
      "blue berry",
      "red berry",
      "pine apple",
      "dragon fruit",
      "cactus fruit",
      "custard apple",
      "lemon",
      "kiwi",
      "strawberry",
      "cholli",
      "cocanut",
      "banana",
      "mango",
      "carrots",
      "cabbage",
      "brocoli",
      "onions"
    ]
  };
  const quertString = qs.stringify(arr1);
  console.log(qs.parse(quertString));

  const arr2 = {
    value: [
      "guava",
      "fig",
      "cherry",
      "blue berry",
      "red berry",
      "pine apple",
      "dragon fruit",
      "cactus fruit",
      "custard apple",
      "lemon",
      "kiwi",
      "strawberry",
      "cholli",
      "cocanut",
      "banana",
      "mango",
      "carrots",
      "cabbage",
      "brocoli",
      "onions",
      'value1',
      'value2'
    ]
  };

  const quertString2 = qs.stringify(arr2);
  console.log(qs.parse(quertString2));
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
    </div>
  );
}

codesandbox: https://codesandbox.io/s/hungry-dijkstra-lyg3fl?file=/src/App.js

query string contains an array with 40 to 50 data. When i try to parse it, it become the object

value: {}

incase array length is less than 21, after parsing also it is array only. How to resolve this issue?

0

There are 0 best solutions below