Javascript examples for Object:Object Keys
Use Object.keys to get all keys from an object
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from ww w . j av a 2 s . c o m*/ var myObj = { 5: "foo", 25: "bar" }; var i=0; Object.keys( myObj ).forEach(function ( name, index ) { var value = myObj[name]; console.log(++i); console.log(name); // the property name console.log(value); // the value of that property console.log(index); // the counter }); } </script> </head> <body> </body> </html>