Gradient
Lesson 1.3Code~1 h

Lists & loops

Store many numbers at once and walk through them — for loops, while loops, map, filter and reduce.

Module 1 · 0/8 done

Lists of things

Machine learning is about lots of data: thousands of examples, millions of numbers. You can’t give each its own variable. Instead you use an array: one name for a whole list, written in square brackets.

Try itArrays
const temps = [18, 21, 25, 19, 23]

console.log(temps[0])          // the FIRST item is at index 0
console.log(temps[2])          // the third item
console.log(temps.length)      // how many items
console.log(temps[temps.length - 1])  // the last item

temps.push(30)                 // add one to the end
console.log(temps)
Press Run (⌘/Ctrl + Enter) to see output here.