Get the current size of the object - Javascript Object

Javascript examples for Object:Object Keys

Description

Get the current size of the object

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <script>
var alerts = {/*from ww  w.  jav  a 2 s .  c  om*/
    1: {app:'a',message:'message'},
    2: {app:'b',message:'another message'}
}

var size = Object.keys(alerts).length

alerts[size + 1] = {app:'Another hello', message:'Another message'}
console.log(alerts)

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

Related Tutorials