Why does array [length] return the first element of a list?

as I know, you can return the length of the array either with

array.length

or

array["length"]

but dropping such quotes

array[length]

will return the first element of the array This is the actual code: var list = [5, 7, 10]; then in the console list [length] returns 5, and I do not have iframes or frames in the window, so window.length or just length returns 0 in the console.

+4
source share
2 answers

You are using window.length.

Returns the number of frames (or <frame>or <iframe>elements) in the window.

var array = [21, 22];

console.log(length);
console.log(window.length);
console.log(array[length]);
<iframe></iframe>
Run codeHide result
+4
source

The length corresponds to a numeric 0, which returns the first element, if it exists.

0, () .

, nodejs, NW.js .., .

+2

Source: https://habr.com/ru/post/1654264/


All Articles