Day 2: Array Search & Slicing
Daily Objective
Section titled “Daily Objective”Search within arrays and modify or extract sub-arrays using slice, splice, join, and sort.
1. Array Methods
Section titled “1. Array Methods”const fruits = ['Apple', 'Banana', 'Orange', 'Mango'];console.log(fruits.includes('Banana')); // trueconsole.log(fruits.indexOf('Orange')); // 2
const copy = fruits.slice(1, 3); // ['Banana', 'Orange'] (non-destructive)fruits.splice(1, 1, 'Blueberry'); // replaces 'Banana' with 'Blueberry' (mutates original)console.log(fruits.join(' - ')); // "Apple - Blueberry - Orange - Mango"Daily Hands-on Practice (70%)
Section titled “Daily Hands-on Practice (70%)”- Sort an array of names alphabetically.
- Sort an array of numbers numerically using
arr.sort((a, b) => a - b).