Gotchas of method in JavaScript method helps to iterate over the array elements. It also helps to manipulate the elements by iterating over it once in correct order.

But will only work on prefilled array. It won't iterate over empty arrays. For example,

// This will work
const authors = ['Param', 'Joshua']; => {
  console.log('authors array ->', author);
  return author;

// This won't work
const emptyAuthors = new Array(6); => {
  console.log('empty array ->', author); // This will never get consoled
  return author;

console.log(emptyAuthors); // [undefined, undefined, undefined, undefined, undefined, undefined]

Then, what is the based way to create empty array that is iterable. You can use Array.fill to populate it,

// Prefill using `Array.fill`
const prefilledAuthors = new Array(3).fill(null);, index) => {
  console.log('prefilled author index ->', index); // This gets consoled
  return author;

You can play with the code here,