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 - 解构数组和交换值的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript ES6 - 解构赋值

JavaScript ES6 - 解构赋值

ES6解构

JavaScript学习笔记 -- ES6学习 变量的解构赋值

03JavaScript程序设计修炼之道 2019-06-04_fe-js-044es6解构赋值之数组解构_2019-06-06_20-10-17 解构赋值数组排序法

JavaScript------解构赋值