Why javscript array accepts string as index
All (normal) property keys get coerced to a string during assignment, if they aren't strings already.
newArr["2"] = 3;
is the same as
newArr[2] = 3;
Arrays are objects, and objects accept arbitrary key-value pairs, so
newArr["a"] = "a";
is legal, it's just very strange to do.
The length
of an array only checks numeric properties, see here:
The length property of this Array object is a data property whose value is always numerically greater than the name of every deletable property whose name is an array index.
By "array index", it means that the property key is numeric.
Note that it's also possible to have a Symbol key, which is the one case where a property key will not be a string:
const sym = Symbol();
const obj = {};
obj[sym] = 'foo';
console.log(typeof sym);
console.log(obj);