Add an object after the last one in an object literal - Javascript Object

Javascript examples for Object:Object Literal

Description

Add an object after the last one in an object literal

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width"> 
   </head> 
   <body> 
      <script>
var alerts = {//from   www  . j  av  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