Skip to content

Instantly share code, notes, and snippets.

@belocer

belocer/index.js

Last active Oct 6, 2020
Embed
What would you like to do?
forEach filter map reduce find
let people = [
{name: 'Mihail', age: 15, budget: 100},
{name: 'Maria', age: 25, budget: 200},
{name: 'Miron', age: 35, budget: 300},
]
people.forEach((person, index, pArr) => {
console.log(person)
console.log(person.name)
console.log(person.age)
console.log(person.budget)
console.log(index)
console.log(pArr)
})
let new_data = people.map(person => person.age * 3)
console.log(new_data)
// 0: 45
// 1: 75
// 2: 105
let adults = people.filter((person, index, pArr) => person.age >= 18)
console.log(adults)
// 0: {name: "Maria", age: 25, budget: 200}
// 1: {name: "Miron", age: 35, budget: 300}
let amount = people.reduce((total, person) => total + person.budget, 2000000)
console.log(amount) // 2000600
let maria = people.find(person => person.name === 'Maria')
console.log(maria) // {name: "Maria", age: 25, budget: 10000}
let igorindex = people.findIndex(person => person.name === 'Maria')
console.log(igorindex) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment