return last item in array conditional javascript code example Example: last element of an array javascript var myArray = [1, 2, 3, 4]; myArray[myArray.length - 1];