10 examples of 'js each function' in JavaScript

Every line of 'js each function' 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
168return function each(callback){
169 if(!context || !context.length){ //arrays and strings only ?? todo: better array checking. Object.prototype.toString(arr) == 'object array'
170 return;// result;// allow chaining to continue? NOTE: referencing result in this function impacts performance. (loss of 100,000 ops per second)
171 }
172 for(var j =0; j < context.length; ++j){
173 callback(j, context[j], nn(context[j]));
174 }
175};
27function _each(object, callback, args) {
28 var name, i = 0,
29 length = object.length,
30 isObj = length === undefined || Object.prototype.toString.apply(object) !== '[object Array]' || typeof object === "function";
31
32 if (args) {
33 if (isObj) {
34 for (name in object) {
35 if (callback.apply(object[name], args) === false) {
36 break;
37 }
38 }
39 } else {
40 for ( ; i < length; ) {
41 if (callback.apply(object[i++], args) === false) {
42 break;
43 }
44 }
45 }
46
47 // A special, fast, case for the most common use of each
48 } else {
49 if (isObj) {
50 for (name in object) {
51 if (callback.call(object[name], name, object[name]) === false) {
52 break;
53 }
54 }
55 } else {
56 for ( ; i < length; ) {
57 if (callback.call(object[i], i, object[i++]) === false) {
58 break;
59 }
60 }
61 }
62 }
63
64 return object;
65}
255export function each(f: (seqNum: number) => T | Promise): Generator {
256 return new Generator(f);
257}
18export function each (value, callback) {
19 return Utility.each(value, callback, {length: 0}, caller)
20}
14function createForEach(arrayFunc, eachFunc) {
15 return function(collection, iteratee, thisArg) {
16 return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
17 ? arrayFunc(collection, iteratee)
18 : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
19 };
20}
170jQuery.fn._each = function _each(callback, args) {
171 return jQuery._each(this, callback, args)
172}
13AlternativeDomWrapper.prototype.each = function each(fn, thisArg) {
14 var i = 0,
15 z = this.elements.length;
16
17 for (; i < z; i++) {
18 fn.call(thisArg || this.elements[i], this.elements[i], i);
19 }
20 return this;
21};
184function each(obj, fn) {
185 return Object.keys(obj).forEach(fn);
186}
3module.exports = function each(fn) {
4 let stop = false;
5
6 if (Array.isArray(this.items)) {
7 this.items.forEach((item, key, array) => {
8 if (!stop) {
9 const output = fn(item, key, array);
10
11 if (output === false) {
12 stop = true;
13 }
14 }
15 });
16 } else {
17 Object.keys(this.items).forEach((key) => {
18 if (!stop) {
19 const output = fn(this.items[key], key, this.items);
20
21 if (output === false) {
22 stop = true;
23 }
24 }
25 });
26 }
27
28 return this;
29};
101function each(obj,callback) {
102 var length = obj.length,
103 i = 0;
104
105 for ( ; i < length; i++ ) {
106 if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { break; }
107 }
108}

Related snippets