JavaScript How to understand array.foo in this case?

I am not sure how to understand this foo property and array here. it looks like foo property got assigned to array, but I don't think it is even valid array syntax. Can someone explain the concept here?

var arr = [];
arr[0]  = 'a';
arr[1]  = 'b';
arr.foo = 'c';
console.log(arr) // ['a','b',foo:'c']  This isn't valid array, but Chrome doesn't show any error.
console.log(arr.foo) // 'c'. 
console.log(arr.length); // 2, not 3
Answer:1

JavaScript arrays are objects plus a few methods and some magic involving the length property, so yes, you can assign random properties to them.

Don't.

(If you run such an array through JSON, those extra properties will be lost.)

Answer:2

I have a little issue that I couldn't figure out. I have a slider and I want to change url when I click prev and next buttons. Here are my codes below but it doesn't work correctly. Every time I click ...

I have a little issue that I couldn't figure out. I have a slider and I want to change url when I click prev and next buttons. Here are my codes below but it doesn't work correctly. Every time I click ...

  1. window location href new tab
  2. window location href relative
  3. window location href not working
  4. window location href vs replace
  5. window location href redirect
  6. window location href javascript
  7. window location href angular
  8. window location href react
  9. window location href mdn
  10. window location href vs assign
  11. window location href jquery
  12. window location href target _blank javascript
  13. window location href in php
  14. window location href reload
  15. window location href is not a function
  16. window location href html
  17. window location href post
  18. window location href encode url
  19. window location href with headers
  20. window location href back

I have a bootstrap popover and its content is a kendo Ui color picker widget. When you click in the color picker widget, the popover close even if the trigger option is set to focus. Why? How to ...

I have a bootstrap popover and its content is a kendo Ui color picker widget. When you click in the color picker widget, the popover close even if the trigger option is set to focus. Why? How to ...

  1. bootstrap popover close button
  2. bootstrap popover not closing
  3. prevent bootstrap popover from closing
  4. closing bootstrap popover

I am using the Ionic framework to build an android app. I have a form as such: <form action='https://secure.payu.in/_payment' method="POST" target="..."> ...... </form> Is there a way ...

I am using the Ionic framework to build an android app. I have a form as such: <form action='https://secure.payu.in/_payment' method="POST" target="..."> ...... </form> Is there a way ...

  1. change formula
  2. change format
  3. change formula excel
  4. change formula to value
  5. change format of date in excel
  6. change format of picture
  7. change formatter vscode
  8. change formula google sheets
  9. change format of date in r
  10. change formatting in word
  11. change format of datetime python
  12. change format of date in sql
  13. change form template
  14. change format of outlook
  15. change format to pdf
  16. change form synonym
  17. change form real estate hawaii
  18. change format of pivot table
  19. change format sas
  20. change form action jquery

Beginning JavaScript learner here... I'm working through Adrian Neumann's Simple Programming Problems and my question is about number 5 in the elementary exercises. Write a program that asks the ...

Beginning JavaScript learner here... I'm working through Adrian Neumann's Simple Programming Problems and my question is about number 5 in the elementary exercises. Write a program that asks the ...

  1. compare contents array javascript
  2. javascript array contents equal
  3. javascript array contents
  4. javascript array contents to string
  5. javascript array contents disappear