JavaScript 내장 객체
JavaScript가 기본으로 제공하는 강력한 객체와 메서드들
Array
String
Math
Date
Object
CHAPTER 01
Array 객체 — 배열 기본 메서드
배열을 다루는 기본 메서드들!
Array 기본 메서드
// length: 배열의 길이
const arr = ["사과", "바나나", "오렌지"];
arr.length; // 3
// indexOf: 요소의 위치 찾기
arr.indexOf("바나나"); // 1
// includes: 포함 여부 확인
arr.includes("사과"); // true
// join: 요소들을 문자열로 합치기
arr.join(", "); // "사과, 바나나, 오렌지"
const arr = ["사과", "바나나", "오렌지"];
arr.length; // 3
// indexOf: 요소의 위치 찾기
arr.indexOf("바나나"); // 1
// includes: 포함 여부 확인
arr.includes("사과"); // true
// join: 요소들을 문자열로 합치기
arr.join(", "); // "사과, 바나나, 오렌지"
실습: Array 메서드
결과가 여기에 나타납니다
const fruits = ["🍎 사과", "🍌 바나나", "🍊 오렌지"];
console.log(`길이: ${fruits.length}`);
console.log(`바나나 위치: ${fruits.indexOf("🍌 바나나")}`);
console.log(`사과 포함?: ${fruits.includes("🍎 사과")}`);
console.log(`결합: ${fruits.join(" | ")}`);
console.log(`길이: ${fruits.length}`);
console.log(`바나나 위치: ${fruits.indexOf("🍌 바나나")}`);
console.log(`사과 포함?: ${fruits.includes("🍎 사과")}`);
console.log(`결합: ${fruits.join(" | ")}`);
CHAPTER 02
String 객체 — 문자열 메서드
문자열을 다루는 강력한 메서드들!
String 메서드
// length: 문자열 길이
const str = "Hello JavaScript";
str.length; // 16
// substring: 부분 추출
str.substring(0, 5); // "Hello"
// split: 문자열을 배열로 분할
str.split(" "); // ["Hello", "JavaScript"]
// toUpperCase / toLowerCase
str.toUpperCase(); // "HELLO JAVASCRIPT"
str.toLowerCase(); // "hello javascript"
// replace: 문자열 치환
str.replace("Hello", "Hi"); // "Hi JavaScript"
const str = "Hello JavaScript";
str.length; // 16
// substring: 부분 추출
str.substring(0, 5); // "Hello"
// split: 문자열을 배열로 분할
str.split(" "); // ["Hello", "JavaScript"]
// toUpperCase / toLowerCase
str.toUpperCase(); // "HELLO JAVASCRIPT"
str.toLowerCase(); // "hello javascript"
// replace: 문자열 치환
str.replace("Hello", "Hi"); // "Hi JavaScript"
실습: String 메서드
결과가 여기에 나타납니다
CHAPTER 03
Math 객체 — 수학 함수들
숫자 계산을 위한 필수 메서드들!
Math 메서드
// Math.floor: 버림
Math.floor(4.7); // 4
// Math.ceil: 올림
Math.ceil(4.2); // 5
// Math.round: 반올림
Math.round(4.5); // 5
// Math.max / Math.min: 최대/최소값
Math.max(10, 20, 5); // 20
Math.min(10, 20, 5); // 5
// Math.random: 0~1 사이 난수
Math.random(); // 0.123456...
Math.floor(4.7); // 4
// Math.ceil: 올림
Math.ceil(4.2); // 5
// Math.round: 반올림
Math.round(4.5); // 5
// Math.max / Math.min: 최대/최소값
Math.max(10, 20, 5); // 20
Math.min(10, 20, 5); // 5
// Math.random: 0~1 사이 난수
Math.random(); // 0.123456...
실습: Math 메서드
결과가 여기에 나타납니다
CHAPTER 04
Date 객체 — 날짜와 시간
현재 시간과 날짜를 다루기!
Date 메서드
// 현재 날짜/시간 생성
const now = new Date();
// 연도, 월, 날짜 가져오기
now.getFullYear(); // 2025
now.getMonth(); // 5 (0-11, 6월)
now.getDate(); // 29
now.getDay(); // 1 (0-6, 월요일)
// 시간, 분, 초
now.getHours(); // 시간
now.getMinutes(); // 분
now.getSeconds(); // 초
const now = new Date();
// 연도, 월, 날짜 가져오기
now.getFullYear(); // 2025
now.getMonth(); // 5 (0-11, 6월)
now.getDate(); // 29
now.getDay(); // 1 (0-6, 월요일)
// 시간, 분, 초
now.getHours(); // 시간
now.getMinutes(); // 분
now.getSeconds(); // 초
실습: Date 메서드
결과가 여기에 나타납니다
CHAPTER 05
Object 메서드 — 객체 다루기
객체의 키와 값을 추출하기!
Object 메서드
// 객체 생성
const user = {
name: "찐망고",
age: 25,
job: "개발자"
};
// Object.keys: 키만 추출
Object.keys(user); // ["name", "age", "job"]
// Object.values: 값만 추출
Object.values(user); // ["찐망고", 25, "개발자"]
// Object.entries: 키-값 쌍으로 추출
Object.entries(user); // [["name", "찐망고"], ...]
const user = {
name: "찐망고",
age: 25,
job: "개발자"
};
// Object.keys: 키만 추출
Object.keys(user); // ["name", "age", "job"]
// Object.values: 값만 추출
Object.values(user); // ["찐망고", 25, "개발자"]
// Object.entries: 키-값 쌍으로 추출
Object.entries(user); // [["name", "찐망고"], ...]
실습: Object 메서드
결과가 여기에 나타납니다