lundi 30 août 2021

After reading the excel file and maping it in the Array in react, Why the last value is always undefined

Sheet Property contains the whole ExcelSheet in JSON format. Dayofthemonth is the Array that contains the value in days (1,2,3....31), which has been mapped from the Sheet. It is working but the also an extra value of undefined in entering in the array after mapping. I have attached the ss of console.log.

I don't understand that where does this undefined value come from.

if anybody knows the Ans and solution, Kindly Help me.

   const GrossProfitView = ({ Sheet }) => {
  

  const Dayofthemonth = [...new Set(Sheet.map((each) => each.Dayofthemonth))];

 
  let DayofthemonthReport = [];
  let DayofthemonthChart = [];

  Dayofthemonth?.forEach((day) => {
    let Days = day;
    let Brokline = 0;
    let EastCostBeast = 0;
    let OneTeam = 0;
    let Thelvy = 0;
    let WestQueens = 0;
    let ThatdayGp = 0;

    Sheet?.forEach((each) => {
      let OverallGP = each.NetProfit;
      let SheetDayofmonth = each.Dayofthemonth;
      let District = each.District;
    
        if (SheetDayofmonth === Days) {
          ThatdayGp = OverallGP + ThatdayGp;

          if (District === "One team One Mission") {
            OneTeam = OverallGP + OneTeam;
          }
          if (District === "West Queens") {
            WestQueens = OverallGP + WestQueens;
          }
          if (District === "The Ivy League") {
            Thelvy = OverallGP + Thelvy;
          }
          if (District === "B.K.S.I") {
            Brokline = OverallGP + Brokline;
          }
          if (District === "East Coast Beasts") {
            EastCostBeast = OverallGP + EastCostBeast;
          }
        }
      
    });
    
    const ThatdayGpChart = {
      GP: Math.round(ThatdayGp),
      EastCostBeast: Math.round(EastCostBeast),
      Brokline: Math.round(Brokline),
      Thelvy: Math.round(Thelvy),
      WestQueens: Math.round(WestQueens),
      OneTeam: Math.round(OneTeam),
      Dayofthemonth: Days,
    };

    DayofthemonthReport.push(ThatdayGpRecord);
   
  });

ss enter image description here

Aucun commentaire:

Enregistrer un commentaire