Javascript examples for Array Operation:Array Element
Increment last array element and show result
<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>