배열에는 숫자, 문자열, 객체등을 함께 넣을 수 있다.
숫자로만 이루어진 배열
const array = [1, 2, 3, 4, 5];
const strArraay = ["감자", "고구마"];
const objects = [{ name: "감자" }, { name: "고구마" }];
const exArray = [2, "문자열",{name:"객체"}];
0
부터 시작한다. console.log(objects[0]);
console.log(objects[1]);
.push
를 이용하여 항목을 추가할 수 있다.배열명.push(값)
의 형태로 작성하면 된다. ex) objects 배열에 객체 추가
objects.push({
name: "딸기"
});
.length
를 이용하여 배열의 크기를 알아낼 수 있다.배열명.length
의 형태로 작성하면 된다.const objects = [{ name: "감자" }, { name: "고구마" }];
console.log(objects.length);
.push
.length