How to skip to next iteration in jQuery.each() util?
By 'return non-false', they mean to return any value which would not work out to boolean false. So you could return true
, 1
, 'non-false'
, or whatever else you can think up.
What they mean by non-false is:
return true;
So this code:
var arr = ["one", "two", "three", "four", "five"];
$.each(arr, function(i) {
if (arr[i] == 'three') {
return true;
}
console.log(arr[i]);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
will log one
, two
, four
, five
.