Why does Array.from() return the first element undefined?

Viewed 4271

When I do

const arrayLike = { 1:'foo', 2:'bar', length:2 };
Array.from(arrayLike);

I get

[ undefined, 'foo' ]

When I do

const arrayLike = { 1:'foo', 2:'bar', length:3 };
Array.from(arrayLike)

I get

[ undefined, 'foo', 'bar' ]
  • Why do I not see bar when I set the length?
  • Why do I see only my elements only when I hard-set the length to 3?
  • Why is the first element showing up as undefined?
2 Answers
Related