Answers for "for of vs for in"

-2

for of vs for in

//for in, iterates keys in an object
var obj={a:1, b:2}

for( var key in obj)
  console.log(obj[key]); //would print 1 and 2

//for of, iterates values in array or any iterable
var ar = [10, 11, 12, 13]
for (var item in ar )
  console.log(item);  //would print 10  11  12  13
Posted by: Guest on August-13-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language