JavaScript map(), filter(), reduce(), find(), forEach()methods

const array = [2,3,6]
const newArray = array.map(e => e + 1)
console.log(newArray) // [3,4,7]
const array = [2,3,6]
const newArray = array.filter(e => e > 3)
console.log(newArray) // [6]
const array = [2,3,6]
const newArray = array.reduce((sum,num) => sum + num, 0)
console.log(newArray) // 11
const array = [-4, 11, 8,30, 32];const found = array.find(element => element > 10);console.log(found); // 11
//use forEach to count each item quantity
const items = ['pencil', 'book','pencil']
const count = {}
items.forEach(item => {
if (count[item]) {
count[item] +=1
return
}
count[item] = 1
})
console.log(count) // {pencil: 2, book: 1}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store