let arr = [1,2,3,4];
[arr[1], arr[2]] = [arr[2], arr[1]];
console.log(arr);
// [1,3,2,4]
반응형
'자바스크립트 > 기초' 카테고리의 다른 글
String.prototype.startsWith() && String.prototype.endsWith() (0) | 2023.06.28 |
---|---|
Math.trunc() (0) | 2023.06.28 |
번들링과 웹팩 (0) | 2021.11.30 |
Callback / Promise / async await (0) | 2021.07.30 |
비동기 (0) | 2021.07.30 |