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