forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
29 lines (24 loc) · 722 Bytes
/
map.js
File metadata and controls
29 lines (24 loc) · 722 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
25
26
27
28
29
// map
// does return a new array
// does not change size of original array
// uses values from original array when making new one
const people = [
{ name: 'bob', age: 20, position: 'developer' },
{ name: 'peter', age: 25, position: 'designer' },
{ name: 'susy', age: 30, position: 'the boss' },
{ name: 'anna', age: 35, position: 'the boss' },
];
const ages = people.map(function (person) {
return person.age + 20;
});
const newPeople = people.map(function (person) {
return {
firstName: person.name.toUpperCase(),
oldAge: person.age + 20,
};
});
const names = people.map(function (person) {
return `<h1>${person.name}</h1>`;
});
document.body.innerHTML = names.join('');
console.log(names);