0

JS array question

why c does not become part of the arr, yet when calling arr.key it exists? var arr = []; arr[0] = "x"; arr[1] = "y"; arr.key = "c"; alert(arr.length);

14th Apr 2017, 10:58 AM
Simon Nadolski
Simon Nadolski - avatar
5 odpowiedzi
+ 2
Similarly, the array methods are also only applied to the elements with numeric indexes.
14th Apr 2017, 11:44 AM
Calviղ
Calviղ - avatar
+ 2
the length property only applied to the elements with numeric indexes.
14th Apr 2017, 11:31 AM
Calviղ
Calviղ - avatar
0
To add new element to a Array use 'push' method. Code: arr.push("c");
14th Apr 2017, 11:23 AM
Thomas Hj
Thomas Hj - avatar
0
Hi Thomas. Thanks for your reply. However, rather than a solution, I am after being able to understand what's happening with c in this example.
14th Apr 2017, 11:27 AM
Simon Nadolski
Simon Nadolski - avatar
0
thanks Calvin. and why when I call the arr it returns only x,y? (not c)
14th Apr 2017, 11:42 AM
Simon Nadolski
Simon Nadolski - avatar