🔖https://developer.mozilla.org/ko/docs/Web/JavaScript/ 를 인용하였음.
arr.slice([begin[, end]])
//ex)1
let fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
let result = fruits.slice(3)
//expected output: ['Apple', 'Mango']
//end인자를 사용하지 않을 시 begin 인덱스부터 마지막 배열 요소까지 나타냄.
//ex)2
let fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
let result = fruits.slice(1, 3)
//expected output: ['Orange','Lemon']
//end에 들어갈 index를 제외하고 추출
//ex)3
let fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango']
let result = fruits.slice(-2)
//expected output: ['Apple', 'Mango']
//인덱스에 음수가 들어갈 시 마지막 배열의 요소에서 가져옴.
array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
//ex)1
let myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
let removed = myFish.splice(2);
// myFish is ["angel", "clown"]
// removed is ["mandarin", "sturgeon"]
//ex)2
let myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
let removed = myFish.splice(-2, 1);
// myFish is ["angel", "clown", "sturgeon"]
// removed is ["mandarin"]
arr.pop()
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
console.log(plants.pop());
// expected output: "tomato"
console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
arr.push(element1[, ...[, elementN]])
//ex)1
let sports = ['축구', '야구'];
let total = sports.push('미식축구', '수영');
console.log(sports); // ['축구', '야구', '미식축구', '수영']
//배열 요소 끝에 추가
//ex)2 (with arr.concat())
// 첫번째 배열에 두번째 배열을 합치기
let vegetables = ['설탕당근', '감자'];
let moreVegs = ['셀러리', '홍당무'];
// vegetables.concat(moreVegs); 하는 것과 동일하다.
Array.prototype.push.apply(vegetables, moreVegs);
console.log(vegetables); // ['설탕당근', '감자', '셀러리', '홍당무']
arr.includes(valueToFind[, fromIndex])
//ex)
[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false
[1, 2, 3].includes(3, 3); // false (인덱스값이 배열의 길이를 넘어서면 false)
[1, 2, 3].includes(3, -1); // true
//fromIndex 가 음수라면, 이 계산된 인덱스는 valueToFind 를 찾기 시작할 배열의 위치로
//사용되기 위해 연산됩니다.
//ex)2
[1, 2, 3].includes(2, -100); // true
//계산된 인덱스가 -1 * array.length 보다 작거나 같다면, 전체 배열이 검색될 것입니다.
[1, 2, NaN].includes(NaN); // true (문자도 판별 가능)
arr.filter(callback, index, array)
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]
let set = new Set(arr);
let pasta = ['tomato', 'basil', 'onion','chicken'];
let pizza = ['tomato', 'cheese', 'onion','olive','beef'];
let result = pasta.concat(pizza); //두 배열을 합친다.
let result_set = [...new Set(result)];
//동작 원리 : 배열을 set객체(object형태)로 저장 및 중복삭제 -> 다시 배열[]로 변환.
arr.toString()
//ex)
const array1 = [1, 2, 'a', '1a'];
console.log(array1.toString());
// expected output: "1,2,a,1a"