* @ngdoc function * @name angular.forEach * @module ng * @kind function * * @description * Invokes the `iterator` function once for each item in `obj` collection, which can be either an * object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value` *
(obj, iterator, context)
| 305 | */ |
| 306 | |
| 307 | function forEach(obj, iterator, context) { |
| 308 | var key, length; |
| 309 | if (obj) { |
| 310 | if (isFunction(obj)) { |
| 311 | for (key in obj) { |
| 312 | // Need to check if hasOwnProperty exists, |
| 313 | // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function |
| 314 | if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) { |
| 315 | iterator.call(context, obj[key], key, obj); |
| 316 | } |
| 317 | } |
| 318 | } else if (isArray(obj) || isArrayLike(obj)) { |
| 319 | var isPrimitive = typeof obj !== 'object'; |
| 320 | for (key = 0, length = obj.length; key < length; key++) { |
| 321 | if (isPrimitive || key in obj) { |
| 322 | iterator.call(context, obj[key], key, obj); |
| 323 | } |
| 324 | } |
| 325 | } else if (obj.forEach && obj.forEach !== forEach) { |
| 326 | obj.forEach(iterator, context, obj); |
| 327 | } else { |
| 328 | for (key in obj) { |
| 329 | if (obj.hasOwnProperty(key)) { |
| 330 | iterator.call(context, obj[key], key, obj); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | return obj; |
| 336 | } |
| 337 | |
| 338 | function sortedKeys(obj) { |
| 339 | return Object.keys(obj).sort(); |
no test coverage detected