6. We made a friend question


I made the code work but I have a question:

What is the var name of the new contact?

for exemple, contacts[0] is bob, contacts[1] is mary, but i didn't declare any var when I created de function add.

If i want to call the first name of the new contact do I have to use contacts[2]?


HI but you did use that


because with that when you call the function add it will makes an object and put it at the last index of the array contacts.


Yes, it is working. But I don't know if it has a var name, or it's just stored at contacts[contacs.length] without a specif name like bob and mary.


oh I seee now .. and NO it doesn't assign name like for bob and mary but it assing it like that

#Empty array

var array = [];
#add something to that array at index 0
array[0] = "JavaScript";
#At index 1
array[1] = "Java";

it put it directly with the index ... in our case we have contacts[contacs.length]


contacts.length would not work as the last index is always one less than the length. This is because indexing starts at 0 instead of 1.


Hi but it will work for putting the object at the last index.

#bob and mary are object 
var contacts = [bob, mary];


but since it starts counting from 0 so so bob will be at 0 marry at 1 and the last one that have been add with contacts[contacs.length] will be at the last index which is 2


That's what I thought, thanks.