es5, es6 수조 반복 방법

5377 단어 #es6

ES5:


1、for
let items=[1,2,3,4,5]
for(let i=0;i<items.length;i++){
    console.log(items[i])	//1 2 3 4 5
}

2、forEach
items.forEach(function(item){    // break、continue
    console.log(item)   //1 2 3 4 5
})

3、every
items.every(function(item){    // return
    console.log(item)   //1 2 3 4 5
    return true
})

4、for in
for (const index in items) {
    console.log(index,items[index])
}
items.a=6
for (const index in items) {	//// , 
    console.log(index,items[index])	
}

ES6


5、for of
let items=[1,2,3,4,5]
for (let item of items) {	// 
    console.log(item)   //1 2 3 4 5
}

좋은 웹페이지 즐겨찾기