List Operations
Initialize
Initialize list and assign to variable.
Python
# empty list
my_list = []
# list with 3 elements
my_list = [1, 2, 3]
JavaScript
const my_list = [1,2,3];
Access Element
Index element in list and assign to variable.
Python
element = my_list[0] # first element 1
JavaScript
my_list[0]; // first element 1
Change Element at Index
Python
# change first element to 100
my_list[0] = 100
JavaScript
my_list[0] = 100;
Add Element to End
Python
# add element to end of list
element = 4
my_list.append(element)
JavaScript
const element = 4;
my_list.push(element);
Remove Element from End
# remove element from end of list
my_list.pop()