How to define array's length without length property?

Viewed 69

I've recently came across this particular code:

const arr = [1,2,3];
const { length } = arr;
for (i = 0; i<=length; i++){
    console.log(i)
}

Apparently this (const { length } = arr;) somehow works, but I haven't found any information on the Internet on either how or why should this actually work.

My question: how does this { } construction work and why doesn't it work when I change { length } to anything else, like { arrlength }? Can we possibly use this construction with other array's properties and how?

0 Answers
Related