본문으로 건너뛰기

꼭 알아야할 Array

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.find((item) => {
return item.name === 'Book'
})

console.log(foundItem)

items.forEach((item) => {
console.log(item.name)
})

// 하나라도
const hasInexpensiveItems = items.some((item) => {
return item.price <= 100
})

console.log(hasInexpensiveItems)

// 모든것이
const hasExpensiveItems = items.every((item) => {
return item.price >= 5
})

console.log(hasExpensiveItems)


// 잘 모르겠다 날 잡고 다시 보잣...
const total = items.reduce((currentTotal, item) => {
return item.price + currentTotal
}, 0)

console.log(total)