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

Popular posts from this blog

c# - Class in a list -

mysql - Django database model for my website -

ios - How to run a segue on itself OR another viewController -