Lesson contents

Read a list by position

Read the value in the position you need. The example picks the second number.

Simple example

Start4 7 9
Result7
lesson.ts
const values: number[] = [4, 7, 9];
console.log(values[1]);
Output
7
Advertisements

Everyday examples

The last three readings were 18, 21 and 19 degrees. Show the middle reading.

Start18 21 19
Result21
lesson.ts
const readings: number[] = [18, 21, 19];
console.log(readings[1]);
Output
21
Run the example
Terminal
tsc --target ES2020 lesson.ts
node lesson.js
Official documentation