일반 unshift() Method

황제낙엽 2009.03.02 13:22 조회 수 : 287 추천:114

sitelink1  
sitelink2  
sitelink3  
sitelink4  
extra_vars4  
extra_vars5  
extra_vars6  
http://www.w3schools.com/jsref/jsref_unshift.aspunshift 펑션은 배열의 0번째에 element를 새로 추가한다. 이때 기존값들은 자동적으로 index가 1 증가한다.

Definition and Usage

The unshift() method adds one or more elements to the beginning of an array and returns the new length.

Syntax

arrayObject.unshift(newelement1,newelement2,....,newelementX)

ParameterDescription
newelement1Required. The first element to add to the array
newelement2Optional. The second element to add to the array
newelementXOptional. Several elements may be added


Tips and Notes

Note: This method changes the length of the array.

Note: The unshift() method does not work properly in Internet Explorer!

Tip: To add one or more elements to the end of an array, use the push() method.


Example

In this example we will create an array, add an element to the beginning of the array and then return the new length:

·미리보기 | 소스복사·
  1. <script type="text/javascript">var arr = new Array();   

  2. arr[0] = 
    "Jani";   
  3. arr[1] = "Hege";   
  4. arr[2] = "Stale";
    document.write(arr + 
    "<br />");   
  5. document.write(arr.unshift("Kai Jim") + "<br />");   
  6. document.write(arr);

    </script>  

The output of the code above will be:

Jani,Hege,Stale
4
Kai Jim,Jani,Hege,Stale


번호 제목 글쓴이 날짜 조회 수
77 [펌] TAEYO.NET - JavaScript OOP 스트레칭 황제낙엽 2009.04.02 27
76 Rhino scopes and contexts 에 대한 문서 황제낙엽 2008.07.18 27
75 Fetch API (CORS 극복을 위한 노력) 황제낙엽 2021.12.05 26
74 유용한 자바스크립트 예제 몇가지 (Tree 및...) file 황제낙엽 2005.10.20 26
73 링크모음 황제낙엽 2011.03.25 25
72 YUI Logger(Yahoo) 를 동적으로 로드하는 북마크릿 황제낙엽 2010.10.03 25
71 생성자 체인과 상속 황제낙엽 2008.08.08 24
70 Date객체 - 날짜구하기 file 황제낙엽 2008.02.19 24
69 CORS(Cross-Origin Resource Sharing) - 2 황제낙엽 2017.03.07 24
68 연산자 this 황제낙엽 2014.12.30 23
67 URI 인코딩을 해야 하는 문자들 황제낙엽 2009.09.02 23
66 [펌] 아사페릴의 사생활 - __proto__ 와 construct 와 prototype 황제낙엽 2009.04.02 23
65 String xml 파싱 황제낙엽 2008.11.03 23
64 XML+JS 연동 다중셀렉트박스 (1) - <font color="brown">(MS Explorer 전용)</brown> 황제낙엽 2005.12.02 23
63 파이어폭스로 스크립트 디버깅하기 황제낙엽 2009.01.14 22
62 동적인 언어를 동적으로 호출하기 file 황제낙엽 2008.07.14 22
61 [펌] TAEYO.NET - JavaScript OOP 코어객체와 prototype를 사용한 객체확장 황제낙엽 2009.04.02 21
60 Object 와 Prototype 황제낙엽 2008.08.08 21
59 [펌]자바스크립트에서 객체 생성 방법 황제낙엽 2008.08.07 21
58 감추기, 보이기 화면 예제 황제낙엽 2008.04.14 21