Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- react with typescript
- 자바 switch문
- 자바 반복문
- 자바 구구단 출력
- 자바 강제 캐스팅
- 자바 while문
- 자바 for문
- MySQL
- 자바 조건문
- 항해99 2기
- 자바 if문
- TypeScript
- 항해99
- 정보처리기사실기
- 타입스크립트
- 자바 삼항연산자
- 이클립스 DB연동
- 자바 스캐너
- 변수
- 자바 공배수
- 자바 향상된 for문
- Vue3
- 조코딩
- Til
- 자바 public
- 프로그래머스
- 자바 자동캐스팅
- java
- 자바
- react ag grid
Archives
- Today
- Total
뇌 채우기 공간
[Java Script] 배열 / 배열의 길이 / 배열안의 값 호출/ 배열에 삽입 본문
const array =[1,2,3,4,5];
console.log(array);
const array2 = [1, 'blabla',{}, 4];
console.log(array2[0]);
console.log(array2[1]);
console.log(array2[2]);
console.log(array2[3]);
const object = [
{name: '멍멍이'},
{name: '야옹이'}
];
console.log(object[0]);
console.log(object[0].name);
[] 이 괄호 사이에 있는 것을 배열이라고 한다.
여러 자료형들을 한 배열에 넣을 수 있다.
index는 0 부터 시작을 한다.
객체 배열도 만들 수 있다.
객체에서 값을 호출하려면, 배열[인덱스].키 이렇게 호출해주면 된다.
const object = [
{name: '멍멍이'},
{name: '야옹이'}
];
console.log(object[0]);
console.log(object[0].name);
object.push({
name: '멍뭉이'
});
// 배열의 길이를 알려준다
console.log(object.length);
console.log(object[2].name);
배열 안에 값을 삽입하려고 하면 push를 쓰면 된다.
그럼 그 다음 인덱스로 값이 삽입된다.
배열의 길이를 알려고 하면 length를 사용하면 된다.
728x90