tubeshowcase●1,129,309 videosβ™‘ My collection 0
← Learn to Code

Learn to Code07:02

JavaScript map() method in 7 minutes! πŸ—ΊοΈ

Bro Code β†—

From the creator

00:00:00 introduciton 00:00:16 example 1 00:02:13 example 2 00:03:58 example 3 // .map() = accepts a callback and applies that function // to each element of an array, then return a new array // ------------ EXAMPLE 1 ------------ const numbers = [1, 2, 3, 4, 5]; const squared = numbers.map(square); const cubed = numbers.map(cube); console.log(cubed); function square(element){ return Math.pow(element, 2); } function cube(element){ return Math.pow(element, 3); } // ------------ EXAMPLE 2 ------------ const students = ["Spongebob", "Patrick", "Squidward", "Sandy"]; const studentsUpper = students.map(upperCase); const studentsLower = students.map(lowerCase); console.log(studentsLower); function upperCase(element){ return element.toUpperCase(); } function lowerCase(element){ return element.toLowerCase(); } // ------------ EXAMPLE 3 ------------ const dates = ["2024-1-10", "2025-2-20", "2026-3-30"]; const formattedDates = dates.map(formatDates); console.log(formattedDates); function formatDates(element){ const parts = element.split("-"); return `${parts[1]}/${parts[2]}/${parts[0]}`; }

Published 2023-11-09 Β· Watch on YouTube β†—
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code