You are on page 1of 2

let arr = [2,3,5,7,9,10]

//Map()
// syntax
let newArray = arr.map(function(currentItem, index, array){
console.log(`Currentitem is ${currentItem} index ${index} array ${arr}`)
return currentItem*2
})

console.log(newArray)

// filter()
let filteredvalues = arr.filter(function(currentItem, index, array){
return currentItem > 5
})

console.log(filteredvalues)

// every()

let age = [22,34,55,67,88,99]

let isAllAdult = age.every(function(currentItem){

return currentItem >= 22

})
console.log(isAllAdult)

//some()

let ageList = [22,34,55,67,88,99]

let isAllAdult1 = ageList.some(function(currentItem){

return currentItem >= 100

})
console.log(isAllAdult1)

// sort()

var names = ["Nikhil","Avinash", "Suresh"]


console.log(names.sort())

// sorting of number

var points = [10,39,12,80,54]

let sortedvalue = points.sort(function(a,b){


return b-a
})
console.log(sortedvalue)

// reduce method

// array.reduce(function(total,currentValue, index, array){

// }, initialValue)
let num = [12, 78 , 30]
let sum = num.reduce(function(total, currentitem){
return total+currentitem
},0)
console.log(sum)

// forEach()
num.forEach(function(currentItem){
console.log(currentItem)
})

Output

Currentitem is 2 index 0 array 2,3,5,7,9,10


script.js:6 Currentitem is 3 index 1 array 2,3,5,7,9,10
script.js:6 Currentitem is 5 index 2 array 2,3,5,7,9,10
script.js:6 Currentitem is 7 index 3 array 2,3,5,7,9,10
script.js:6 Currentitem is 9 index 4 array 2,3,5,7,9,10
script.js:6 Currentitem is 10 index 5 array 2,3,5,7,9,10
script.js:10 (6) [4, 6, 10, 14, 18, 20]
script.js:17 (3) [7, 9, 10]
script.js:28 true
script.js:39 false
script.js:44 (3) ['Avinash', 'Nikhil', 'Suresh']
script.js:53 (5) [80, 54, 39, 12, 10]
script.js:65 120
script.js:69 12
script.js:69 78
script.js:69 30

You might also like