[jquery] JavaScript Array splice() Method
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
출처 : http://www.w3schools.com/jsref/jsref_splice.asp
JavaScript Array splice() Method
Example
Add items to the array:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,0,"Lemon","Kiwi");
fruits.splice(2,0,"Lemon","Kiwi");
The result of fruits will be:
Banana,Orange,Lemon,Kiwi,Apple,Mango
Try it yourself »
Definition and Usage
The splice() method adds/removes items to/from an array, and returns the removed item(s).
Note: This method changes the original array.
Browser Support
The splice() method is supported in all major browsers.
Syntax
array.splice(index,howmany,item1,.....,itemX)
Parameter Values
Parameter | Description |
---|---|
index | Required. An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array |
howmany | Required. The number of items to be removed. If set to 0, no items will be removed |
item1, ..., itemX | Optional. The new item(s) to be added to the array |
Return Value
Type | Description |
---|---|
Array | A new array containing the removed items, if any |
Technical Details
JavaScript Version: | 1.2 |
---|
More Examples
Example
At position 2, add the new items, and remove 1 item:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");
fruits.splice(2, 1, "Lemon", "Kiwi");
The result of fruits will be:
Banana,Orange,Lemon,Kiwi,Mango
Try it yourself »
Example
At position 2, remove 2 items:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 2);
fruits.splice(2, 2);
The result of fruits will be:
Banana,Orange
Try it yourself »
'Web > javascript / jQuery' 카테고리의 다른 글
[jQuery] 여러 버튼의 클릭에 이벤트 바인딩 하는 방법 (2) | 2015.04.27 |
---|---|
[jQuery] jQuery 에서 시간값 반올림 (2) | 2015.04.27 |
[jquery] 이전 페이지, 앞 페이지로 이동 및 새로고침 (2) | 2015.04.16 |
[Troble shooting] Uncaught ReferenceError (2) | 2015.04.16 |
자바스크립트 즉시 실행 함수의 불편한 진실 (4) | 2015.04.16 |