$.each
var arr = [1, 2, 'test', 3, 4, 5, 6]
// break
$.each(arr, function(index, value) {
if (value == 'test') {
return false
}
console.log('-----------------break', value)
})
// continue
$.each(arr, function(index, value) {
if (value == 'test') {
return true
}
console.log('-----------------continue', value)
})
// return
function test() {
try {
$.each(arr, function(index, value) {
if (value == 'test') {
throw('')
}
console.log('-----------------return', value)
})
} catch(e) {
return
}
}
test()
forEach
var arr = [1, 2, 'test', 3, 4, 5, 6]
var everyNumber = arr.every(function(value, index) {
console.log(value, index)
return typeof(value) == 'number'
})
function isString(value) {
console.log(value)
return typeof(value) == 'string'
}
var someString = arr.some(isString)
console.log(everyNumber)
console.log(someString)