in JavaScript by

Which one of the given code will be equivalent for the following JavaScript code:

for(var p in o)  

   console.log(o[p]);  

a) Code A

for (var i = 1;i<a.length;i++)  

console.log(a[i]);  

b) Code B

for (var i = 0;i<a.length;i++)  

console.log(a[i]);  

C) Code C

for (int i = 0;i<a.length;i++)  

console.log(a[i]);  

d) Code D

for (var i = 0;i<= a.length;i++)  

console.log(a[i]);  

1 Answer

0 votes
by

Answer: A

Reason: The variable in the code A working same ( e.g. traversing the array from the 0 index value) just like it working in the above code. In addition, we can also use the "For-in" loop statement for performing the same task more efficiently.

Related questions

0 votes
asked Mar 22, 2021 in JavaScript by Robindeniel
0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
...