Increment last array element and show result - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Increment last array element and show result

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* ww  w. j  a  v  a 2s.com*/
var someArray = [0,0,7,1,2,3];
   var incrementLastArrayElement = function(_array) {
       var newArr = _array.slice();
       newArr[newArr.length - 1]++;
       return newArr;
   }
console.log(incrementLastArrayElement(someArray));
    }

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

Related Tutorials