forEachRight.js

  1. import createForEach from './internals/createForEach';
  2. /**
  3. * 迭代集合元素(从右往左的顺序),为每个元素调用 `iteratee`。
  4. *
  5. * `iteratee` 函数可以通过显式返回 `false` 来提前退出迭代。
  6. *
  7. * `iteratee` 调用时会传入三个参数 `value` `index|key` `collection`。
  8. *
  9. * @function
  10. * @alias module:Collection.forEachRight
  11. * @since 1.7.0
  12. * @param {ArrayLike<any> | Object} collection 要迭代的集合。
  13. * @param {Function} [iteratee=identity] 每次迭代调用的函数。默认 `identity`。
  14. * @returns {ArrayLike<any> | Object} 迭代集合本身。
  15. * @example
  16. *
  17. * forEachRight([1,2,3], function(item){
  18. * console.log(item);
  19. * });
  20. * // 3
  21. * // 2
  22. * // 1
  23. *
  24. * forEachRight({a: 1, b: 2}, function(value, key){
  25. * console.log(value, key);
  26. * });
  27. * // 2 'b'
  28. * // 1 'a'
  29. *
  30. */
  31. const forEachRight = createForEach(-1);
  32. export default forEachRight;