July 13, 2023
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
- Declare two variable
a
andb
- Initialize two variable with value of array
a = ["Html", "Css", "JavaScript","Html","Css"]
andb = a.lastIndexOf("Html")
- Array
lastIndexOf()
method returns the last index of the given element - 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
- Declare two variable
c
andd
- Initialize two variable with value of array
c = ["Html", "Css", "JavaScript","Html","Css","JavaScript"]
andd = c.lastIndexOf("Css")
- Array
lastIndexOf()
method returns the last index of the given element - The value of
d
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
avaScript Array lastIndexOf()