Array Length returns 0

arrays, javascript

Solution

Because that is not how you add an item since Arrays only accept numeric keys. You do it like this:

errors.push("blah");  /*or*/  errors[0] = "blah";

//Now if you check the length:
errors.length;  //1

Also, if you are using it as an Object, `''` isn't a valid name either.

*Correction: Looks like you can use `""` (empty string) as a key.

Problem

Could anyone help explain why length is returning 0? Thank you VERY much in advance! ``` var errors = []; errors[''] = "Monday Morning slot already taken. Would you like to replace it?"; console.log(errors); document.write(errors.length); ```

Original source