get first element of arraylist javascript code example

Example 1: javascript get first element of array

let array = [1,2,3] // makes your array
array[0] // returns first element of your array.

Example 2: java get first element from arraylist

import java.util.ArrayList;
public class FirstandLastElemets{
   public static void main(String[] args){
      ArrayList<String> list = new ArrayList<String>();
      //Instantiating an ArrayList object
      list.add("JavaFX");
      list.add("Java");
      list.add("WebGL");
      list.add("OpenCV");
      list.add("OpenNLP");
      list.add("JOGL");
      list.add("Hadoop");
      list.add("HBase");
      list.add("Flume");
      list.add("Mahout");
      list.add("Impala");
      System.out.println("Contents of the Array List: \n"+list);
      //Removing the sub list
      System.out.println("First element of the array list: "+list.get(0));
      System.out.println("Last element of the array list: "+list.get(list.size()-1));
   }
}

Example 3: javascript get first element of array

let mylist = ['one','two','three','last'];
mylist[0],mylist[1],mylist[2],mylist[3];//this is called indexing and slicing in python
//in javascript it called getting elements in array