MCPcopy
hub / github.com/axios/axios / forEach

Function forEach

lib/utils.js:370–406  ·  view source on GitHub ↗

* Iterate over an Array or an Object invoking a function for each item. * * If `obj` is an Array callback will be called passing * the value, index, and complete array for each item. * * If 'obj' is an Object callback will be called passing * the value, key, and complete object for each proper

(obj, fn, { allOwnKeys = false } = {})

Source from the content-addressed store, hash-verified

368 * @returns {any}
369 */
370function forEach(obj, fn, { allOwnKeys = false } = {}) {
371 // Don't bother if no value provided
372 if (obj === null || typeof obj === 'undefined') {
373 return;
374 }
375
376 let i;
377 let l;
378
379 // Force an array if not already something iterable
380 if (typeof obj !== 'object') {
381 /*eslint no-param-reassign:0*/
382 obj = [obj];
383 }
384
385 if (isArray(obj)) {
386 // Iterate over array values
387 for (i = 0, l = obj.length; i < l; i++) {
388 fn.call(null, obj[i], i, obj);
389 }
390 } else {
391 // Buffer check
392 if (isBuffer(obj)) {
393 return;
394 }
395
396 // Iterate over object keys
397 const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
398 const len = keys.length;
399 let key;
400
401 for (i = 0; i < len; i++) {
402 key = keys[i];
403 fn.call(null, obj[key], key, obj);
404 }
405 }
406}
407
408/**
409 * Finds a key in an object, case-insensitive, returning the actual key name.

Callers 5

mergeFunction · 0.85
extendFunction · 0.85
reduceDescriptorsFunction · 0.85
visitFunction · 0.85
forEach.test.jsFile · 0.85

Calls 1

isBufferFunction · 0.85

Tested by

no test coverage detected