10 examples of 'lodash foreach' in JavaScript

Every line of 'lodash foreach' 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
57function forEach(o, fn) {
58 if (Array.isArray(o)) {
59 return o.forEach(fn);
60 }
61 else {
62 for (var key in o) {
63 if (o.hasOwnProperty(key)) {
64 fn(o[key], key)
65 }
66 }
67 }
68}
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

52function forEach(array, iterator) {
53 for (var index = 0; index < array.length; index += 1) {
54 iterator(array[index], index);
55 }
56}
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}
1026export function foreach<V>(obj: { [key: string]: V }, action: (key: string, value: V) => void) {
1027
1028 for (const name in obj) {
1029 if (obj.hasOwnProperty == null || obj.hasOwnProperty(name)) {
1030 action(name, obj[name]);
1031 }
1032 }
1033}
9function forEach (arr, callback) {
10 arr && arr.forEach(callback);
11}
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}
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}
25function forEach(value, fn, path) {
26 path = path || '';
27
28 if (Array.isArray(value)) {
29 forEachArray(value, fn, path);
30 } else if (isPlainObject(value)) {
31 forEachObject(value, fn, path);
32 }
33}
25function forEach(object, callback, context) {
26 var index, length;
27 if (object.length) {
28 if (Array.prototype.forEach) {
29 Array.prototype.forEach.call(object, callback, context);
30 } else {
31 for (index = 0, length = object.length; index < length; index += 1) {
32 callback.call(context || this, object[index], index, object);
33 }
34 }
35 } else {
36 for (index in object) {
37 if (object.hasOwnProperty(index)) {
38 callback.call(context || this, object[index], index, object);
39 }
40 }
41 }
42}
53var forEach = function forEach(list, iteratee) {
54 var record = arguments[2] === undefined ? { index: 0 } : arguments[2];
55
56 for (var i = 0, len = list.length; i < len; i += 1) {
57 var item = list[i];
58 if (isArr(item)) {
59 forEach(item, iteratee, record);
60 } else if (!isUndefined(item)) {
61 iteratee(item, record.index);
62 record.index += 1;
63 }
64 }
65};

Related snippets