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 |
Tags
- js
- UI
- es6
- addEventListener
- Dom
- keyboardEvent
- Temporal dead zone
- Event
- react
- javascript
- a11y
- modal
- innerText
- for loop
- HTML
- keyup
- node
- css:position
- textContent
- TypingEffect
- Review
- node.js
- CSS
- innerHTML
- Empty
- dotenv
- nodeValue
- ES5
- beforeinput
- yet
Archives
- Today
- Total
the murmurous sea
JS ES1: slice() 본문
1. returns the selected elements in an array.
2. as a new array object.
3. a new array object is selected from begin to end.
4. end not included.
5. the begin and end represent the index of items in that array.
6. The original array will not be modified.
7. can also be called to convert Array-like objects / collections to a new Array. (MDN doc)
[Syntax]
arr.slice([begin[, end]])
begin | Optional | An integer that specifies where to start the selection | |
Zero-based index | |||
At which to begin extraction. | |||
A negative index can be used, indicating an offset from the end of the sequence. | |||
If begin is undefined, | slice begins from index 0. | ||
If begin is greater than the index range of the sequence, | an empty array is returned. | ||
end | Optional | An integer that specifies where to end the selection. | |
Zero-based index | |||
Before which to end extraction. (slice extracts up to but not including end.) | |||
A negative index can be used, indicating an offset from the end of the sequence. | |||
If end is omitted, | all elements from the start position and to the end of the array will be selected(arr.length). | ||
If end is greater than the length of the sequence, | extracts through to the end of the sequence (arr.length). |
[Return Value]
A new Array, containing the selected elements
[Example]
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var myBest = fruits.slice(-3, -1);
console.log (myBest);
//returns ["Lemon", "Apple"]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
'#dev > 개념정리' 카테고리의 다른 글
DOM: Node.nodeValue (0) | 2020.05.05 |
---|---|
DOM: nodeValue vs. textConent vs. innerText vs. innerHTML (0) | 2020.05.04 |
JS, ES1: splice() (0) | 2020.05.04 |
JS, ES1: split() (0) | 2020.05.04 |
JS: padStart() & padEnd() (0) | 2020.05.04 |
Comments