자바스크립트(javascript) 배열(array) 사용
Language/JAVASCRIPT 2011. 7. 27. 14:271. 배열생성
var array_test = new Array();
2. push 메소드 사용
Definition and Usage
The push() method adds new elements to the end of an array, and returns the new length.
Note: This method changes the length of an array!
Syntax
array.push(element1, element2, ..., elementX) |
Parameter | Description |
---|---|
element1, element2, ..., elementX | Required. The element(s) to add to the end of the array |
Example
ExampleAdd new elements to the end of an array, and return the new length:
The output of the code above will be:
|
3. join 메소드 사용
Definition and Usage
The join() method joins all elements of an array into a string, and returns the string.
The elements will be separated by a specified separator. The default separator is comma (,).
Syntax
array.join(separator) |
Parameter | Description |
---|---|
separator | Optional. The separator to be used. If omitted, the elements are separated with a comma |
Example
ExampleJoin all elements of an array into a string:
The output of the code above will be:
|
출처 - http://www.w3schools.com/jsref/jsref_obj_array.asp
JavaScript Array Object
Array Object
The Array object is used to store multiple values in a single variable.
For a tutorial about Arrays, read our JavaScript Array Object tutorial.
Array Object Properties
Property | Description |
---|---|
constructor | Returns the function that created the Array object's prototype |
length | Sets or returns the number of elements in an array |
prototype | Allows you to add properties and methods to an object |
Array Object Methods
Method | Description |
---|---|
concat() | Joins two or more arrays, and returns a copy of the joined arrays |
indexOf() | |
join() | Joins all elements of an array into a string |
pop() | Removes the last element of an array, and returns that element |
push() | Adds new elements to the end of an array, and returns the new length |
reverse() | Reverses the order of the elements in an array |
shift() | Removes the first element of an array, and returns that element |
slice() | Selects a part of an array, and returns the new array |
sort() | Sorts the elements of an array |
splice() | Adds/Removes elements from an array |
toString() | Converts an array to a string, and returns the result |
unshift() | Adds new elements to the beginning of an array, and returns the new length |
valueOf() | Returns the primitive value of an array |
- 출처 : http://blog.naver.com/fromyongsik
[출처] 자바스크립트 javascript에서 배열 array 사용하기|작성자 네오 에이치
'Language > JAVASCRIPT' 카테고리의 다른 글
자바스크립트 맵, javaScript Map (0) | 2011.08.09 |
---|---|
클래스명으로 엘리멘트 얻기, getElementsByClassName() (0) | 2011.08.09 |
[javascript] typeof 연산자 ExtJS / WEB2.0 (0) | 2011.07.25 |
User Agent 파헤치기 (navigator.userAgent) (0) | 2011.07.13 |
firefox, IE 이벤트(event) 얻기 (0) | 2011.06.14 |