Home > Enterprise >  why empty slots are being replaced with undefined while cloning array using spread syntax?
why empty slots are being replaced with undefined while cloning array using spread syntax?

Time:12-03

I'm creating a clone array from an array that contain some empty slots. But after cloning it is being replaced with undefined. If the source array contain some empty slots then clone array should also contain same number and at exact same position empty slots. I don't get the reason. I'm using enter image description here

CodePudding user response:

Using spread syntax will invoke the object's iterator if it has one. The array iterator will:

a. Let index be 0.
b. Repeat
  Let len be ? LengthOfArrayLike(array).
  iii. If index ≥ len, return NormalCompletion(undefined).
  (...)
    1. Let elementKey be ! ToString(           
  • Related