Skip to content

Commit 36d8ef5

Browse files
feat : added map array iterator
1 parent b3be6ac commit 36d8ef5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Array Methods/map.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// map
2+
// does return a new array
3+
// does not change size of original array
4+
// uses values from original array when making new one
5+
6+
const people = [
7+
{ name: 'bob', age: 20, position: 'developer' },
8+
{ name: 'peter', age: 25, position: 'designer' },
9+
{ name: 'susy', age: 30, position: 'the boss' },
10+
{ name: 'anna', age: 35, position: 'the boss' },
11+
];
12+
13+
const ages = people.map(function (person) {
14+
return person.age + 20;
15+
});
16+
const newPeople = people.map(function (person) {
17+
return {
18+
firstName: person.name.toUpperCase(),
19+
oldAge: person.age + 20,
20+
};
21+
});
22+
23+
const names = people.map(function (person) {
24+
return `<h1>${person.name}</h1>`;
25+
});
26+
27+
document.body.innerHTML = names.join('');
28+
29+
console.log(names);

0 commit comments

Comments
 (0)