Hey Redditors,

As the title suggests I am trying to put all the objects that I mapped into a single array. The problem is if I keep the arrayIt() within the map function (as shown in figure below) they produce individual arrays packed with their own objects due to the map. But if I keep the arrayIt() outside the map() only the last object gets saved in the array because they are overwritten repeatedly due to map().

Post image
 coordinateValues = () => {
    let data;
    this.props.provinceNames.map((e) => {
      data = { date: e.Date, totalCases: e.Cases };

      // Function for putting mapped objects into an array
      const arrayIt = function (...array) {

      xAndYValue: data,

How can I do it so that all the objects get saved into one array?

Thank you very much for your help! Stay safe & happy coding…

Source link

Write A Comment