````
let arr = [1, 2, 3, 4, 5]
let text = ''
for (let v of arr) {
if (v === 3) {
break
}
text += v + ','
}
console.log(text) // "1,2,"
````.
使用some进行代码优化
````
let arr = [1, 2, 3, 4, 5]
let text = ''
arr.some(v => {
if (v === 3) {
return true
}
text += v + ','
})
console.log(text) // "1,2,"
````
网友评论