-
Notifications
You must be signed in to change notification settings - Fork 0
/
file57.js
56 lines (44 loc) · 1.17 KB
/
file57.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use strict";
// map method
// map function is like for each loop but it creates new array let's see how it works
const numbers = [32,43,45,64];
// function decalre
// function square (number) {
// return number*number;
// }
// function expression
// const square = function(number){
// return number*number;
// }
// function arrow
// const square = (number) => {
// return number*number;
// }
// const answer = numbers.map(square);
// console.log(answer);
// we can do this in one line
// const myAns = numbers.map(function square(number){
// return number * number ;
// })
// console.log(myAns);
// what if i use arrow function there
// let square = [];
// const myAns = numbers.map(square =(numbers) => {
// return numbers*numbers;
// } )
// console.log(myAns);
// let's do more short
// const myAns = numbers.map((numbers) => {
// return numbers*numbers;
// });
// console.log(myAns);
// let's do realstic example
const users = [
{firstName : "jitendra",age:23},
{firstName : "ankit",age:21},
{firstName : "punit",age:20}
]
const returnedValue = users.map(function accesNames(name){
return name.firstName;
});
console.log(returnedValue);