I have the following JavaScript code:
var name = ui.item.label.split('. ', 2);
name.lastname = name[0];
name.firstname = name[1];
The split() method is used to split a string into an array of substrings, and returns the new array. However, I want to reference the array associatively. So, I re-assigned name as shown above.
Did I just add two more elements to the name array or say are name[0] and name.lastname the same element?
If I’m correct I created the following array of length 4…
name.0
name.1
name.lastname
name.firstname
You added two more properties to the array object, but not numeric indices. It’s not an “array of length 4”, it’s an “array of length 2, with two custom properties on it”.