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

837 B
Raw Blame History

title localeTitle
Use Destructuring Assignment to Assign Variables from Objects 使用解构分配从对象分配变量

使用解构分配从对象分配变量

这个挑战需要一些关于javascript中的字符串对象的直觉。

创建字符串对象时,它基于以下字符串原型

因此,每个字符串都具有长度属性; genericString = {length13}。 这是String.prototype中唯一采用的属性。

使用解构重新分配属性。

var basicOjb = {x: 40}; 
 //To reassign 'get the value of the x property of basicObj and place its value into bigX' in ES6: 
 const { x: bigX } = basicOjb; 
 consle.log(bigX) // ans = 40 

将'str'的length属性值放入len中。