Program to use JavaScript Array entries() method
let a = [ 'Cat', 'Dog', 'Tiger', 'Lion', 'Elephant' ];
let b = a.entries();
for(let c of b){
console.log(c);
}
Output
[ 0, 'Cat' ]
[ 1, 'Dog' ]
[ 2, 'Tiger' ]
[ 3, 'Lion' ]
[ 4, 'Elephant' ]
Steps Description
- Declare three variables
a, b
andc
- Initialize three variables with array value respectively
a = [ 'Cat', 'Dog', 'Tiger', 'Lion', 'Elephant' ], b = a.entries()
andc
- Array entries() method returns the index number of the array.
- The value of
c
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array entries() method
let d = [3,5,7,2,8];
let e = d.entries();
for(let f of e){
console.log(f);
}
Output
[ 0, 3 ]
[ 1, 5 ]
[ 2, 7 ]
[ 3, 2 ]
[ 4, 8 ]
Steps Description
- Declare three variables
d, e
andf
- Initialize three variables with array value respectively
d = [3,5,7,2,8], e = d.entries()
andf
- Array entries() method returns the index number of the array.
- The value of
f
variable is displayed with the help of console.log inbuilt function