배열 순서를 반전해줌. ['1','2','3'] -> ['3','2','1']
const array1 = ['one', 'two', 'three'];
const reversed = array1.reverse();
console.log('reversed:', reversed);
// expected output: "reversed:" Array ["three", "two", "one"]
// 원본 array1도 변경함.
console.log('array1:', array1);
// expected output: "array1:" Array ["three", "two", "one"]
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse
'언어 정리 > JavaScript' 카테고리의 다른 글
String.prototype.repeat() (0) | 2022.11.12 |
---|---|
Array.prototype.sort() (0) | 2022.11.12 |
String.prototype.split() (0) | 2022.11.09 |
Array.prototype.join() (0) | 2022.11.09 |
Array.proptotype.filter() (0) | 2022.11.06 |