You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

for-each.js 448B

12345678910111213141516171819202122
  1. const getKeys = require('./get-keys');
  2. const isArrayLike = require('./is-array-like');
  3. const optimizeCb = require('./optimize-cb');
  4. module.exports = (obj, iteratee, context) => {
  5. iteratee = optimizeCb(iteratee, context);
  6. if (isArrayLike(obj)) {
  7. let i = 0;
  8. for (const item of obj) {
  9. iteratee(item, i++, obj);
  10. }
  11. } else {
  12. const keys = getKeys(obj);
  13. for (const key of keys) {
  14. iteratee(obj[key], key, obj);
  15. }
  16. }
  17. return obj;
  18. };