How to remove array from Json object React Native

  javascript, json, react-native, reactjs

i want a output of my array :

[
  {
    "discount": "0",
    "id": "2",
    "image": "https://punjabfoodhub.in/app/food_image/Dominos-Veg-Pizza-Margherita.jpg",
    "main_prise": "140",
    "name": "Margherita (Medium) 8""
  },
  {
    "discount": "0",
    "id": "3",
    "image": "https://punjabfoodhub.in/app/food_image/Dominos-Veg-Pizza-Margherita.jpg",
    "main_prise": "170",
    "name": "Margherita (Large) 10""
  }
]

But my output is :

[
  {
    "discount": "0",
    "id": "2",
    "image": "https://punjabfoodhub.in/app/food_image/Dominos-Veg-Pizza-Margherita.jpg",
    "main_prise": "140",
    "name": "Margherita (Medium) 8""
  },
  [
    {
      "discount": "0",
      "id": "3",
      "image": "https://punjabfoodhub.in/app/food_image/Dominos-Veg-Pizza-Margherita.jpg",
      "main_prise": "170",
      "name": "Margherita (Large) 10""
    }
  ]
]

So how can I achieve my required output?

my code is

fetch('https://punjabfoodhub.in/app/reg.php', {
  method: 'POST',
  mode: 'no-cors',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    item_id: ids,
    func: 'item_data',
  }),
})
  .then((response) => response.json())
  .then((json) => {
    if (this.state.item_data.length == 1) {
      var temp = [];
      temp = this.state.item_data;
      temp.push(json);
      this.setState({ item_data: temp });

      console.log(this.state.item_data);
    } else {
      this.setState({ item_data: json });
    }
    //this.state.item_data.push(json);
  })
  .catch((err) => {
    console.log(err);
  });

Source: Ask Javascript Questions

LEAVE A COMMENT