Object Array length returns undefined in JavaScript -
i have array displayed below in console.
console.log(roles); user {0: "adminuser", 1: "authenticateduser"}
although array unable array length.
console.log(roles.length); undefined
but if access array using index, able value shown below.
console.log(roles[0]); adminuser
it not array, object.
the reason why can access using array-like notation js supports square brackets access notation. since have numbers keys, can bit misleading.
Comments
Post a Comment