Created
October 10, 2019 11:40
-
-
Save tomshaw/334fe80e28b54162546e8e31cabb3762 to your computer and use it in GitHub Desktop.
8 Must Know JavaScript Array Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Web Dev Simplified | |
// 8 Must Know JavaScript Array Methods | |
// https://www.youtube.com/watch?v=R8rmfD9Y5-c | |
const items = [ | |
{ name: 'Bike', price: 100 }, | |
{ name: 'TV', price: 200 }, | |
{ name: 'Album', price: 10 }, | |
{ name: 'Book', price: 5 }, | |
{ name: 'Phone', price: 500 }, | |
{ name: 'Computer', price: 1000 }, | |
{ name: 'Keyboard', price: 25 }, | |
]; | |
const filteredItems = items.filter((item) => { | |
return item.price <= 100 | |
}) | |
console.log(filteredItems); | |
const itemNames = items.map((item) => { | |
return item.name | |
}); | |
console.log(itemNames); | |
const foundItem = items.map((item) => { | |
return item.name === 'Book' | |
}); | |
console.log(foundItem); | |
items.forEach((item) => { | |
console.log(item.name); | |
}) | |
let hasInexpensiveItems = items.some((item) => { | |
return item.price <= 100 | |
}); | |
console.log(hasInexpensiveItems); | |
let hasInexpensiveItems = items.every((item) => { | |
return item.price <= 1000 | |
}); | |
console.log(hasInexpensiveItems); | |
const total = items.reduce((currentTotal, item) => { | |
return item.price + currentTotal | |
}, 0); | |
console.log(total); | |
const numbers = [1, 2, 3, 4, 5] | |
const includesTwo = numbers.includes(2) | |
console.log(includesTwo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment