dgvirtual Posted August 19, 2020 Share Posted August 19, 2020 I was fiddling with „Accessing Arrays with Named Indexes“ section examples of the Javascript tutorial and run into a situation I cannot understand. In short, I create an array 'person', then add elements to the array by index, and then add a third element by name. According to the tutorial, this should convert the array to an object (see here: https://www.w3schools.com/js/js_mistakes.asp) . Instead, after this I can access the variable 'person' as both an array (with two elements) and an object (or rather, a person.age property of the object). typeof 'person' reports: object. var person = []; person[0] = "John"; person[1] = "Doe"; person["age"] = 46; Here is a link to the full test: https://www.w3schools.com/code/tryit.asp?filename=GHWDV13H8E0Z Could someone explain what is happening here? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now