get index code example

Example 1: Javascript get last item in array

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

Example 2: python find index by value

>>> ["foo", "bar", "baz"].index("bar")
1

Example 3: python index of item in list

list.index(element)

Example 4: how to index python

#you can index in a string like:
string='cupcake'
string[0]#returns 'c'
#you can index in a list like:
list = ['red', 'blue', 'green']
list[0]#returns 'red'
list[0][0]#returns[0] of 'red' wich is r

Example 5: python, list, index function

# vowels list
vowels = ['a', 'e', 'i', 'o', 'i', 'u']

# index of 'e' in vowels
index = vowels.index('e')
print('The index of e:', index)

# element 'i' is searched
# index of the first 'i' is returned
index = vowels.index('i')

print('The index of i:', index)