0

I can't find description about this code in JS...

    let arr = [3, 1, 5, 1, 2, 1, 1];

    let { length } = arr;

    console.log(length);

why this code work like arr.length and how should I call it?

  • That's... just how destructing works. `let { length } = arr;` is equivalent to `let length = arr.length;`. It extracts the `length` property of the object and puts it into a variable named `length` – CertainPerformance Jul 20 '22 at 22:30
  • @CertainPerformance thx for your answer. Could I ask you two more questions??? First, is it possible to check what kind of properties are included?? And... does array object has only one instance property "length"?? – vaaast_lake Jul 21 '22 at 04:08
  • You can iterate over own properties of an object with `Object.keys` or `Object.getOwnPropertyNames` depending on whether you care about enumerability. The array has other instance properties too - the array indicies, like `1` and `2` – CertainPerformance Jul 21 '22 at 04:10

0 Answers0