JavaScript Tutorial

JavaScript Arrays

Source: Programming with Mosh

Arrays with Real API Data

Production apps rarely loop over fruit lists. You work with API payloads — like Spotify playlist tracks returned from the Web API.

  • map — transform each track into UI-ready data
  • filter — narrow results (e.g. songs over 3 minutes)
  • reduce — aggregate totals (playlist duration, popularity scores)
Note: This sandbox uses the Spotify Web API response shape. Requests are mocked locally — no API key required.
Fetch & transform playlist tracks
const res = await fetch(
  "https://api.spotify.com/v1/playlists/37i9dQZEVXbMDoHDONVNfs/tracks?limit=5"
);
const { items } = await res.json();
const names = items.map((item) => item.track.name);
console.log(names);
Discover Weekly — map, filter, reduce

Console

// Click Run — watch API traces and console output