Jump to content
  • 0

последний элемент массива


DivMan
 Share

Question

Вот написано, то, что, если для массива написать свойство length, то должно вывестись последний номер + 1, получается то, что ничего.

 

а в этом примере, выводится последний, почему?

 

var arr = ["bmw", "lada", "camaro", "uaz"]var last = arr[length]alert(last)

 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Нумерация элементов массива начинается с 0, а не с 1. Поэтому в массиве с 4-мя элементами последний индекс будет 3, а не 4. А length возвращает именно количество элементов, а не максимальный индекс.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy