* @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)
| 309 | */ |
| 310 | |
| 311 | function forEach(obj, iterator, context) { |
| 312 | var key, length; |
| 313 | if (obj) { |
| 314 | if (isFunction(obj)) { |
| 315 | for (key in obj) { |
| 316 | // Need to check if hasOwnProperty exists, |
| 317 | // as on IE8 the result of querySelectorAll is an object without a hasOwnProperty function |
| 318 | if (key != 'prototype' && key != 'length' && key != 'name' && (!obj.hasOwnProperty || obj.hasOwnProperty(key))) { |
| 319 | iterator.call(context, obj[key], key, obj); |
| 320 | } |
| 321 | } |
| 322 | } else if (isArray(obj) || isArrayLike(obj)) { |
| 323 | var isPrimitive = typeof obj !== 'object'; |
| 324 | for (key = 0, length = obj.length; key < length; key++) { |
| 325 | if (isPrimitive || key in obj) { |
| 326 | iterator.call(context, obj[key], key, obj); |
| 327 | } |
| 328 | } |
| 329 | } else if (obj.forEach && obj.forEach !== forEach) { |
| 330 | obj.forEach(iterator, context, obj); |
| 331 | } else { |
| 332 | for (key in obj) { |
| 333 | if (obj.hasOwnProperty(key)) { |
| 334 | iterator.call(context, obj[key], key, obj); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | return obj; |
| 340 | } |
| 341 | |
| 342 | function sortedKeys(obj) { |
| 343 | return Object.keys(obj).sort(); |
no test coverage detected