javascript ES6 - 解构数组和交换值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES6 - 解构数组和交换值相关的知识,希望对你有一定的参考价值。

let inRing = 'Hulk Hogan';
let onSide = 'The Rock';

console.log(inRing, onSide);
/* This might look a bit funky but what's happening is pretty simple: On the right
hand side we've got an array with the original values. As we give an array, we can 
destructure it, which we do on the lefthand side. We destructure the array renaming
the `onSide` value to `inRing`and the `inRing` value to `onSide`*/
[inRing, onSide] = [onSide, inRing];
console.log(inRing, onSide);

以上是关于javascript ES6 - 解构数组和交换值的主要内容,如果未能解决你的问题,请参考以下文章