How to use JavaScript Array keys()

Program to use JavaScript Array keys() method


let a = ["JavaScript","Python","Php","Css","Html"];
let b = a.keys();

for(let key of b){
    console.log(key);
}

Output


0
1
2
3
4

Steps Description

  1. Declare three variable a, b and key
  2. Initialize three variable with value of array a = ["JavaScript","Python","Php","Css","Html"], b = a.keys() and key
  3. Array keys() method returns the index number of the given array.
  4. The value of key variable is displayed with the help of console.log inbuilt function

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

How to use JavaScript Array fill()

Program to use JavaScript Array fill() method


let a = ["JavaScript","Python","Php","Css","Html"];
let b = a.fill("Java");
console.log(b);

Output


[ 'Java', 'Java', 'Java', 'Java', 'Java' ]

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ["JavaScript","Python","Php","Css","Html"] and b = a.fill("Java")
  3. Array fill() method fills the elements of the array with the given value.
  4. The value of b variable is displayed with the help of console.log inbuilt function

Program to use JavaScript Array fill() method


let c = ["JavaScript","Python","Php","Css","Html"];
let d = c.fill("Java",1,3);
console.log(d);

Output


[ 'JavaScript', 'Java', 'Java', 'Css', 'Html' ]

Steps Description

  1. Declare two variable c and d
  2. Initialize two variable with value of array c = ["JavaScript","Python","Php","Css","Html"] and d = c.fill("Java",1,3)
  3. Array fill() method fills the elements of the array with the given value.
  4. The value of d variable is displayed with the help of console.log inbuilt function

How to use JavaScript Array indexOf()

Program to use JavaScript Array indexOf() method


let a = ["JavaScript","Python","Php"];
let b = a.indexOf("Python");
console.log(b);

Output


1

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = ["JavaScript","Python","Php"] and b = a.includes("Python")
  3. Array IndexOf() method returns the index value of the array if it is found in the given array and returns -1 if it is not found.
  4. The value of b variable is displayed with the help of console.log inbuilt function