-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmap.js
More file actions
24 lines (15 loc) · 687 Bytes
/
map.js
File metadata and controls
24 lines (15 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Using function declaration
const countries = ['Finland', 'Estonia', 'Sweden', 'Norway']
const newCountries = countries.map(function (country) {
return country.toUpperCase()
})
console.log(newCountries)
// map using an arrow function call back
const countries = ['Finland', 'Estonia', 'Sweden', 'Norway']
const newCountries = countries.map((country) => country.toUpperCase())
console.log(newCountries) // ["FINLAND", "ESTONIA", "SWEDEN", "NORWAY"]
const countriesLength = countries.map(country => country.length)
console.log(countriesLength) // [7, 7, 6, 6]
const numbers = [1, 2, 3, 4, 5]
const squares = numbers.map(n => n ** 2)
console.log(squares) // [1, 4, 9, 16, 25]