Koans
Array.slice()
The slice()
method returns a shallow copy of a portion of an array into a new array object selected from begin
to end
(end
not included). The original array will not be modified.
Array.slice(a) : a번째 array object부터 출력한다.
Array.slice(a, b) : a번째부터 b번째 앞까지의 array object를 출력한다.
JavaScript Demo:
Array.pop()
The pop()
method removes the last element from an array and returns that element. This method changes the length of the array.
Array.pop() : 맨 마지막 array object를 제거하고 그 요소(element)를 출력한다.
JavaScript Demo:
Array.unshift()
The unshift()
method adds one or more elements to the beginning of an array and returns the new length of the array.
Array.unshift() : array 앞에 새로운 element를 삽입한다.
JavaScript Demo:
Array.shift()
The shift()
method removes the first element from an array and returns that removed element. This method changes the length of the array.
Array.shift() : array에서 첫 번째 element를 제거한다.
JavaScript Demo:
in 연산자
// 배열
var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
0 in trees // true를 반환합니다.
3 in trees // true를 반환합니다.
(1 + 2) in trees // true를 반환합니다. 연산자 우선 순위에 의하여 이 구문의 괄호는 없어도 됩니다.
6 in trees // false를 반환합니다.
"bay" in trees // false를 반환합니다. 당신은 배열의 내용이 아닌, 인덱스 값을 명시하여야 합니다.
"length" in trees // true를 반환합니다. length는 Array(배열) 객체의 속성입니다.
// 미리 정의된 객체
"PI" in Math // true를 반환합니다.
"P" + "I" in Math // true를 반환합니다.
// 사용자가 정의한 객체
var myCar = {company: "Lamborghini", model: "Lamborghini Veneno Roadster", year: 2014};
"company" in myCar // true를 반환합니다.
"model" in myCar // true를 반환합니다.