{
const fruits = ["apple", "banana", "orange"];
console.log(fruits.join(""));
console.log(fruits.join(","));
console.log(fruits.join("|"));
}
{
const fruits = "🍎, 🥝, 🍌, 🍒";
console.log(fruits.split(","));
console.log(fruits.split(","));
}
{
const array = [1, 2, 3, 4, 5];
console.log(array.reverse());
}
{
const array = [1, 2, 3, 4, 5];
const result = array.splice(0, 2);
console.log(array);
console.log(result);
}
{
const array = [1, 2, 3, 4, 5];
const result = array.slice(0, 3);
console.log(array);
console.log(result);
}
class Student {
constructor(name, age, enrolled, score) {
this.name = name;
this.age = age;
this.enrolled = enrolled;
this.score = score;
}
}
const students = [
new Student("A", 29, true, 45),
new Student("B", 28, false, 80),
new Student("C", 30, true, 90),
new Student("D", 40, false, 66),
new Student("E", 18, true, 88),
];
{
const result = students.find((student) => student.score === 90);
console.log(result);
}
{
const result = students.filter((student) => student.enrolled);
console.log(result);
}
{
const result = students.map((student) => student.score);
console.log(result);
}
{
const result = students.some((student) => student.score < 50);
console.log(result);
const result2 = students.every((student) => student.score < 50);
console.log(result2);
}
{
const result = students.reduce((prev, curr) => prev + curr.score, 0);
console.log(result / students.length);
}
{
const result = students
.map((student) => student.score)
.filter((score) => score >= 50)
.join();
console.log(result);
}
{
const result = students
.map((student) => student.score)
.sort((a, b) => a - b)
.join();
console.log(result);
}
references
자바스크립트 8. 배열 제대로 알고 쓰자. 자바스크립트 배열 개념과 APIs 총정리