▷ shift()
- 배열에서 첫번째 요소를 제거(배열의 길이가 바뀜)
- 제거한 값을 반환
const array1 = [1, 2, 3];
const firstElement = array1.shift();
console.log(array1);
// expected output: Array [2, 3]
console.log(firstElement);
// expected output: 1
▷ pop()
- shift와 유사, 마지막 요소를 제거한다는 점이 다름
const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
console.log(plants.pop());
// expected output: "tomato"
console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
plants.pop();
console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage"]
▷ Object.values()
- 객체가 갖는 모든 '필드'의 값을 배열로 얻음
const o = { a: 10, b: 20 }
Object.values(o) // [10, 20]
▷ Object.entries()
- 객체가 갖는 모든 필드의 '키, 값' 쌍을 반환
const o = { a: 10, b: 20}
Object.entries(o) // [['a', 10], ['b', 20]]
[오늘의 기록]
- 어제 오늘 배운 게 내가 한달동안 공부한 내용보다 많은 것 같다
- 배운 내용들을 무지성으로 다 쓰려고 하지말고, 최근에도 사용되는 기능인지 기능 내에 오류는 없는지 경계할 것
- 쉬는 시간 있을 때 array와 관련된 함수들 정리할 것, 코딩테스트 문제 푸는 데 도움될 것 같다
- 최선을 다하고, 어쩔 수 없는 건 그냥 그렇게 두기, 일단 하는데까지!
'Development > TIL' 카테고리의 다른 글
[TIL] 2022-01-18 (input tag properties, arrow function) (0) | 2022.01.18 |
---|---|
[TIL] 2021-11-17 (find) (0) | 2021.11.18 |
[TIL] 2021-09-10 (0) | 2021.09.14 |
[TIL] 2021-08-24 (0) | 2021.08.26 |
[TIL] 2021-08-04 (0) | 2021.08.05 |
댓글