'TypeError: undefined is not an object (evaluating 'R[k].payment')

I have problem with this table because I want to show them two kind of date. One has length 180element and second 300 elements. The problem is if I loop through it and I put more then first element have, I get error


TypeError: undefined is not an object (evaluating 'R[k].payment')

I try to somehow solve, but do not now any solutions. It is my attempt:

   const array = [];
   for (var k = 0; k < chart1.length ; k++) 
    { 
      array.push({
      "name": "miesiąc" + " " + parseFloat(k+1),
     "email":  R[k].payment.length < chart1.length ? R[k].payment : 0
   })}

  setDatess(array )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source