MCPcopy Create free account
hub / github.com/CoderOpen/waimai / forEach

Function forEach

front/utils/luch-request/utils.js:61–86  ·  view source on GitHub ↗
(obj, fn)

Source from the content-addressed store, hash-verified

59 * @param {Function} fn The callback to invoke for each item
60 */
61export function forEach (obj, fn) {
62 // Don't bother if no value provided
63 if (obj === null || typeof obj === 'undefined') {
64 return
65 }
66
67 // Force an array if not already something iterable
68 if (typeof obj !== 'object') {
69 /*eslint no-param-reassign:0*/
70 obj = [obj]
71 }
72
73 if (isArray(obj)) {
74 // Iterate over array values
75 for (var i = 0, l = obj.length; i < l; i++) {
76 fn.call(null, obj[i], i, obj)
77 }
78 } else {
79 // Iterate over object keys
80 for (var key in obj) {
81 if (Object.prototype.hasOwnProperty.call(obj, key)) {
82 fn.call(null, obj[key], key, obj)
83 }
84 }
85 }
86}
87
88/**
89 * 是否为boolean 值

Callers

nothing calls this directly

Calls 1

isArrayFunction · 0.85

Tested by

no test coverage detected