freeCodeCamp/guide/chinese/certifications/javascript-algorithms-and-d.../es6/use-destructuring-assignmen.../index.md

490 B
Raw Blame History

title localeTitle
Use Destructuring Assignment to Assign Variables from Arrays 使用解构分配从数组中分配变量

使用解构分配从数组中分配变量

在这种情况下,我们必须采取一些预防措施。

  1. 不需要const [ba]因为它将保持赋值局部的效果。

  2. const [ba] = [ab]将导致ab的值为undefined从左到右的简单赋值规则

因此,这个问题的解决方案是 [ba] = [ab]