ES6: Use Destructuring Assignment to Assign Variables from Objects

I’m completely confused as to how to include destructuring into this assignment.

I know how to find the string length, but I’m a little confused as to what’s going on here.

My wild guess at the solution:

function getLength(str) {
“use strict”;

// change code below this line
const lengths = [str.length];
const [dicts] = lengths;
const len = dicts // change this
// change code above this line

return len; // you must assign length to len in line

}

console.log(getLength(‘FreeCodeCamp’));

change it in line and assign it. const { length: len } = str

Thanks! That worked! What in the world is going on inside that code though?

const { length } = str is destructuring, so instead of writing const length = str.length you could write the first one.
const { length : len } = str is assigning const length to len. So you dont need to write
const len = length;
Hope u get it :slight_smile:

That helps a lot – thanks!!