- Published on
JS - ES6 for-of
ES5 for-in Array
var list = ['a', 'b', 'c']
for (var index in list) {
console.log(list[index])
}
//result
//a
//b
//c
ES6 for-of Array
var list = ['a', 'b', 'c']
for (var val of list) {
console.log(val)
}
//result
//a
//b
//c
ES5 for-in String
var str = 'abc'
for (var index in str) {
console.log(str[index])
}
//result
//a
//b
//c
ES6 for-of String
var str = 'abc'
for (var char of str) {
console.log(char)
}
//result
//a
//b
//c