get the last item in an array 1

get the last item in an array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1];//get last item in the array

Here is what the above code is Doing:
1. Create an array called colors with three strings.
2. Create a variable called green and set it equal to the last item in the colors array.

Similar Posts