Skip to content

Instantly share code, notes, and snippets.

@belocer
Last active October 6, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save belocer/5060a5ffb1762f87607c729dbfab42b3 to your computer and use it in GitHub Desktop.
Save belocer/5060a5ffb1762f87607c729dbfab42b3 to your computer and use it in GitHub Desktop.
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