0

I am facing this unexpected behavior using array.push as you can see the array districts have a length of 1 but when you open it its empty.

code:

  districts_modules.forEach((item) => {
    item.modules_id.forEach((insight) => {
      userRoles[modules[parseInt(insight) - 1]].buildings.push({
        districtName: item.districtName,
        districtId: item.district_id,
        buildings: [],
      });

      userRoles[modules[parseInt(insight) - 1]].districts.push({
        label: item.districtName,
        value: item.district_id,
      });
      console.log(userRoles[modules[parseInt(insight) - 1]]);
    });
  });

enter image description here

i don't know why this happening. any explanation.

adel
  • 3,436
  • 1
  • 7
  • 20
  • 1
    how are you pushing value there? Seems there are some other operation performed after pushing the value – brk May 14 '20 at 09:47
  • 1
    Maybe this? https://stackoverflow.com/questions/35637106/array-is-showing-up-as-empty-yet-it-contains-values –  May 14 '20 at 09:48
  • @brk added the code . – adel May 14 '20 at 09:49

0 Answers0