Use associative array to store objects - Javascript Array Operation

Javascript examples for Array Operation:Associative Array

Description

Use associative array to store objects

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <script type="text/javascript">
var id=2;/* ww  w  .jav  a2  s .  co m*/
var myArray={}
myArray["sede_"+ id] = "ciao";
myArray["sede_"+ (++id)] = "espresso";
var len = 0;
for (var o in myArray) {
    if (myArray.hasOwnProperty(o)) len++;
}
myArray.length=len;
console.log(myArray.length)

      </script>  
   </body>
</html>

Related Tutorials