10 examples of 'foreach array jquery' in JavaScript

Every line of 'foreach array jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
79function forEach(array, callback, scope) {
80 for (var i = 0; i < array.length; i++) {
81 callback.call(scope, i, array[i]); // passes back stuff we need
82 }
83}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

389function forEach (array, callback, thisObj)
390 {
391 for (var i=0; i<array.length; i++)
392 {
393 if (array.hasOwnProperty(i))
394 {
395 callback.call(thisObj, array[i], i, array);
396 }
397 }
398}
100function forEach(array, callback) {
101 for (var i = 0; i < array.length; i++) {
102 callback(array[i], i);
103 }
104}
1function forEach(array, action) {
2 for (var i = 0; i < array.length; i++ )
3 action(array[i]);
4}
6function forEach(arr, callback, thisObj) {
7 if (arr == null) {
8 return;
9 }
10 var i = -1,
11 n = arr.length;
12 while (++i < n) {
13 // we iterate over sparse items since there is no way to make it
14 // work properly on IE 7-8. see #64
15 if ( callback.call(thisObj, arr[i], i, arr) === false ) {
16 break;
17 }
18 }
19}
30function each(array, fn) {
31 if (typeof array.forEach === "function") return array.forEach(fn);
32
33 for (var i = 0; i < array.length; i++) fn(array[i], i);
34}
35function foreach(arr, fn) {
36 if (!arr) return;
37
38 if (arr instanceof Array) {
39 for (var i=0; i<arr.length; i++) {
40 fn(arr[i], i);
41 }
42 } else {
43 for (attr in arr) {
44 fn(arr[attr], attr);
45 }
46 }
47}
1255function foreach(array, fn){
1256 var i = 0,
1257 len = array.length;
1258
1259 for(; i < len; i ++){
1260 fn(array[i], i);
1261 }
1262};
11function forEach(array, callback, scope, splice) {
12 for (var all = [].concat(array), index = 0, length = all.length; index < length; ++index) {
13 if (splice) {
14 array.splice(index, 1);
15 }
16
17 callback.call(scope, all[index], index, array, scope);
18 }
19}
9function forEach (arr, callback) {
10 arr && arr.forEach(callback);
11}

Related snippets