fill Array Method | JavaScript Tutorial

preview_player
Показать описание

In this tutorial we're going to learn about the #fill #JavaScript #Array Method and how it can be used to change the elements inside of an array with a specific value. Optionally we can provide a start and an end index.

---
Support my channel:
Thank you! 🙏

---

---
Follow me on:
Рекомендации по теме
Комментарии
Автор

An other solution that I like better is the from() static method of Array.
The first argument is any iterable, like an array, a string or an object. So you can specify an object with unique property length. The second argument is just a callback that maps each element of the newly created Array.

const fillInNumbers = n => Array.from({ length: n }, (_, i) => i)

jeromesnail
Автор

I'm confused, we are adding numbers in this part (indx + 1). Why are we creating "items" as numbers instead of an empty length of spaces? I mean we are working with de index parameter not the item. Hope you can understand my question.

DericksonCaballero
Автор

Hi Florin Pop. I have one question. What is the _ for first argument in map method?

muadzrosli
Автор

I have a small doubt here... instead of [ 1, 2, 3 ]...I need [ { num : 1 }, { num : 2 } ]...is there any way ??

balakrishnanyukesh
Автор

what is "Array" inside the function

jent