8000 array map · last-endcode/JavaScript-Basics@0cbc16e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0cbc16e

Browse files
committed
array map
1 parent 458cca8 commit 0cbc16e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

36_array_map.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// return new array
2+
//not change size of original array
3+
//uses values from original array when making new one
4+
5+
const people = [
6+
{ name: 'bobo', born: 1987, position: 'developer' },
7+
{ name: 'peter', born: 1989, position: 'designer' },
8+
{ name: 'sussy', born: 1975, position: 'the boss' },
9+
{ name: 'Jane', born: 1999, position: 'the boss' },
10+
];
11+
12+
// const born = people.map(function () {});
13+
// console.log(ages);
14+
/*output:
15+
[ undefined, undefined, undefined ]
16+
*/
17+
18+
const borns = people.map(function (item) {
19+
return `The member company is ${item.person} as ${item.position}`;
20+
});
21+
console.log(borns);
22+
23+
// example again use return as objects
24+
const names = people.map(function (item) {
25+
//create obj firstName and age
26+
return {
27+
firstName: item.name,
28+
age: 2020 - item.born,
29+
};
30+
});
31+
32+
console.log(names);

0 commit comments

Comments
 (0)
0