for
for (var i=0; i < 3; i++) {
if (1==i) {
return ;
}
console.log(i)
}
for (var i=0; i < 3; i++) {
if (1==i) {
break;
}
console.log(i)
}
for-of
var arr=[3,2,0,3,5]
var obj={
0: 'nick',
1: 'freddy',
2: 'mike',
5: 'james'
};
arr.name='tom'
for(let item of arr){
if(item<2) return
console.log('of',item);
}
for(let item of arr){
if(item<2) break
console.log('of',item);
}
for(let item of arr){
console.log('of',item);
}
for(let item of obj){
console.log('of',item);
}
var arr=[3,2,0,3,5]
arr.name='tom'
Object.keys(arr)
for-in
var arr=[3,2,0,3,5];
arr.name='tom'
var obj={
0: 'nick',
1: 'freddy',
2: 'mike',
5: 'james'
};
arr.name='tom'
for(let item in obj){
console.log('in',item);
}
for(let item in arr){
console.log('in',item);
}
for(let item in obj){
if(item>2) break
console.log('in',item);
}
for(let item in obj){
if(item>2) return
console.log('in',item);
}
forEach
arr.forEach(v=>{
if(v<3) break;
console.log('forEach',v)
});
arr.forEach(v=>{
if(v<3) return ;
console.log('forEach',v)
});
|