source: node_modules/es-toolkit/dist/compat/array/forEach.mjs@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 680 bytes
Line 
1import { identity } from '../../function/identity.mjs';
2import { range } from '../../math/range.mjs';
3import { isArrayLike } from '../predicate/isArrayLike.mjs';
4
5function forEach(collection, callback = identity) {
6 if (!collection) {
7 return collection;
8 }
9 const keys = isArrayLike(collection) || Array.isArray(collection) ? range(0, collection.length) : Object.keys(collection);
10 for (let i = 0; i < keys.length; i++) {
11 const key = keys[i];
12 const value = collection[key];
13 const result = callback(value, key, collection);
14 if (result === false) {
15 break;
16 }
17 }
18 return collection;
19}
20
21export { forEach };
Note: See TracBrowser for help on using the repository browser.