Array from Method

preview_player
Показать описание
JavaScript has an Array method called from( ) which will allow us to quickly and easily create a shallow copy of an Array.

Рекомендации по теме
Комментарии
Автор

3 minutes, every things about shallow copy is cleared., a feat that can only done by you. Thank you.

rotrose
Автор

function monkeyCount(n) {
return Array.from({length :n}, (_, i) => i + 1)
}

Hi there. Could you, please, explain that example above? The purpose of the function is create array from one to given (n) number, but how does it work?

Thanks in advance!

DmitriAlõvajev
Автор

so Array.from() is basically the same as [...names]

js_programmer
Автор

Hey Steve, thanks for the video (funnily enough, I just saw .from() chained between an array variable and a forEach() loop in another video about an hour ago). I was wondering, when/why do you think something like .from() would be used? I didn't particularly grasp why it was used in the example I came across, and not totally sure when/why one would use this as opposed to copying an array with slice. Thanks!

michaelblum
Автор

Thank for explaining it in a easy and understandable way :)

Tommyandersen
Автор

Thank for your clear explanation, but I also saw an example of using array: Array.from({length: 5}, (v, i) => i); the object "{length:5}" tell the Array.from() method to generate an array with the specified length. Just found out you did not cover this part:)

panpanzhang
Автор

We can just assign one array to other instead of this right?

JS-zmse
Автор

thanks Steve! great explanation can you please create more of these videos? :)

dhahn
Автор

How to make a full copy of inner objects, too?

indigosay