📜  for of vs for in - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:13.957000             🧑  作者: Mango

代码示例1
//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