Create a Shallow Copy of an Array with Slice

Shane Osbourne
InstructorShane Osbourne
Share this video with your friends

Social Share Links

Send Tweet
Published 9 years ago
Updated 5 years ago

Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a 'shallow' copy is and how it can trip people up. We go on to look at examples that show to how to copy only the first item, the last item and even how to copy a sub-section of an array excluding the first and last. We end the lesson with a practical example that shows how slice fits into a workflow that contains other array methods such as map & reduce.

Joshua
Joshua
~ 8 years ago

pretty cool. like this.

Mike
Mike
~ 7 years ago

Awesome example at the end.

Amit
Amit
~ 6 years ago

Why on earth do you mix map and reduce here, i have no clue what they do, similarly in earlier example , you have used file objects like path, this is terrible .. i am not understanding any thing here ... sorry but when i pay , i expect better

Janis
Janis
~ 5 years ago

I don't understand the syntax. :? For prev next, how does prev figure out it's 'Shane Osbourne' and then moves over the elements? I need more info here

Lucas
Lucas
~ 5 years ago

What does => do? I've not seen it before.

Oktana
Oktana
~ 5 years ago

I don't understand the syntax. :? For prev next, how does prev figure out it's 'Shane Osbourne' and then moves over the elements? I need more info here.

That is how reduce work, we pass the ref variable that contains the value 'Shane Osbourne' , ref is the initial value passed to reduce ex: items.reduce(callbackFn, initialValue);

Hope you get it now, Regards. jzamit

Oktana
Oktana
~ 5 years ago

What does => do? I've not seen it before.

It is an arrow function used with an implicit return, ex: const name = 'jzamit'; console.log(name => name.toUpperCase()); // JZAMIT

Hope you get it now, Regards. jzamit

Krishna  Haranath
Krishna Haranath
~ 3 years ago

the ending was so confusing

Markdown supported.
Become a member to join the discussionEnroll Today