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

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -