➕ More Array Methods
- slice - copies a portion on an array
- splice - removes/replaces elements
- sort - sorts an array
🧬 slice() - copies a portion on an array
let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
colors.slice();
colors.slice(3);
colors.slice(5);
colors.slice(1);
let coolColors = colors.slice(3);
coolColors;
colors
colors.slice(2, 4);
colors.slice(0, 3);
let warmColors = colors.slice(0,3);
warmColors;
colors
colors.slice(-3);
colors.slice(-2);
🔧 splice - removes/replaces elements
let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
colors.splice(5, 1)
colors
let days = ["Monday", "Tuesday", "Wednesday"]
days.splice(1, 2);
days
colors
colors.splice(1, 0, 'red-orange')
colors
colors.splice(4, 0, 'yellow-green', 'forestgreen')
colors
🧂 sort - sorts an array
let scores = [1, 70, 100, 2500, 9, -12, 0, 34]
scores.sort()