JavaScript For Beginners #37 | How To Copy Arrays Without Messing Up!

Опубликовано: 21 Март 2026
на канале: Dev Diva
12
2

📚 Watch the full JavaScript For Beginners course here:    • JavaScript For Beginners | Full Tutorial  

00:00 - Array references explained
01:45 - Copy array using spread operator
02:16 - Copy using slice() and concat()
02:48 - Shallow vs deep copy
03:49 - Deep copy using JSON.parse()
04:37 - Exercise
04:50 - Example solution

📚 Resources:
Source code: https://github.com/devdivatutorials/j...

Copy: Exercise
1. Declare an array of numbers [1, 2, 3, 4].
2. Make a copy of numbers and modify the first element in the copy to be 10.
3. Declare an array of people:
let people = [
{name: "Mark", age: 21},
{name: "Lucy", age: 16}
]
4. Make a shallow copy and add a new person {name: "Jane", age: 30}.
5. Make another copy and change the name “Mark” to “Jason” without affecting the original array.

📚 CSS & HTML For Beginners full course:    • HTML & CSS for Beginners