Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

roadmap

6. 배열 본문

web programming/JavaScript

6. 배열

kdw_w 2020. 8. 5. 20:52

 

 

 

 

javascript의 배열은 진정한 의미의 배열이 아닌 배열처럼 다룰 수 있는 동적 자료구조이다

js에서는 배열은 추가 기능을 조금 지닌 객체이다

typeof연산자를 콘솔에 입력해보자

1
2
  var array = [1,2,3,4,5,6,7,"string"];
 typeof array; // 'object'
cs

 

 

 

C나 자바 같은 언어는 배열이 가질 수 있는 원소의 개수를 지정하고, 개수가 변하지 않는다

그러나 자바스크립트는 임의 개수의 원소를 가졌으며 언제든 변경(삭제,추가)할 수 있다

 

자바스크립트의 배열은 Array클래스의 인스턴스이며, Array 클래스의 다양한 메서드를 호출할 수 있다

이렇게 배열과 유사한 객체들은 실제 배열의 원소들에 대해 반복 작업을 하는 알고리즘을 그대로 활용할 수 있다

(배열을 문자열로 바꾸거나 다양한 정렬 알고리즘, 특정 위치에 삽입 등등)

가장 대표적인 것은 배열의 길이를 가지고 있는 length 프로퍼티이다

 

다양한 배열 메서드들을 확인 할 수 있다

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/length

 

Array.prototype.length

The length property of an object which is an instance of type Array sets or returns the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.

developer.mozilla.org

 

 

 

'web programming > JavaScript' 카테고리의 다른 글

8. 변수의 유효 범위(scope chain)  (0) 2020.08.07
7. 예외 처리  (0) 2020.08.05
5. 객체  (0) 2020.08.05
4. 값과 참조  (0) 2020.08.05
3. 메모리 구조  (0) 2020.08.05