JavaScript

July 13, 2023

How to use JavaScript Array lastIndexOf()

Program to use JavaScript Array lastIndexOf() method


let a = ["Html", "Css", "JavaScript","Html","Css"];
let b = a.lastIndexOf("Html");
console.log(b);

Output


3

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ["Html", "Css", "JavaScript","Html","Css"] and b = a.lastIndexOf("Html")
  3. Array lastIndexOf() method returns the last index of the given element
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array lastIndexOf() method


let c = ["Html", "Css", "JavaScript","Html","Css","JavaScript"];
let d = c.lastIndexOf("Css");
console.log(d);

Output


4

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable with value of array c = ["Html", "Css", "JavaScript","Html","Css","JavaScript"] and d = c.lastIndexOf("Css")
  3. Array lastIndexOf() method returns the last index of the given element
  4. The value of d variable is displayed with the help of console.log inbuilt function

by : Suhel Akhtar

Quick Summary:

avaScript Array lastIndexOf()