Iterates over elements of `collection` and invokes `iteratee` for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning `false`. **Note:** As with other "Collections" methods, objects with a "length" property are iterated like arrays. To avoid this behavior use `forIn` or `forOwn` for object iteration.
forEach([1, 2], value => console.log(value))
// => Logs `1` then `2`.
forEach({ 'a': 1, 'b': 2 }, (value, key) => console.log(key))
// => Logs 'a' then 'b' (iteration order is not guaranteed).
| Name | Type | Attribute | Description |
|---|---|---|---|
| collection | The collection to iterate over. | ||
| iteratee | The function invoked per iteration. |
{
"comment": "/**\r\n * Iterates over elements of `collection` and invokes `iteratee` for each element.\r\n * The iteratee is invoked with three arguments: (value, index|key, collection).\r\n * Iteratee functions may exit iteration early by explicitly returning `false`.\r\n *\r\n * **Note:** As with other \"Collections\" methods, objects with a \"length\"\r\n * property are iterated like arrays. To avoid this behavior use `forIn`\r\n * or `forOwn` for object iteration.\r\n *\r\n * @since 0.1.0\r\n * @alias each\r\n * @category Collection\r\n * @param {Array|Object} collection The collection to iterate over.\r\n * @param {Function} iteratee The function invoked per iteration.\r\n * @returns {Array|Object} Returns `collection`.\r\n * @see forEachRight, forIn, forInRight, forOwn, forOwnRight\r\n * @example\r\n *\r\n * forEach([1, 2], value => console.log(value))\r\n * // => Logs `1` then `2`.\r\n *\r\n * forEach({ 'a': 1, 'b': 2 }, (value, key) => console.log(key))\r\n * // => Logs 'a' then 'b' (iteration order is not guaranteed).\r\n */",
"meta": {
"range": [
1088,
1233
],
"filename": "forEach.js",
"lineno": 28,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100002894",
"name": "forEach",
"type": "FunctionDeclaration",
"paramnames": [
"collection",
"iteratee"
]
},
"vars": {
"func": "each~func"
}
},
"description": "Iterates over elements of `collection` and invokes `iteratee` for each element.\rThe iteratee is invoked with three arguments: (value, index|key, collection).\rIteratee functions may exit iteration early by explicitly returning `false`.\r\r**Note:** As with other \"Collections\" methods, objects with a \"length\"\rproperty are iterated like arrays. To avoid this behavior use `forIn`\ror `forOwn` for object iteration.",
"since": "0.1.0",
"alias": "each",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Collection",
"value": "Collection"
}
],
"params": [
{
"type": {
"names": [
"Array",
"Object"
]
},
"description": "The collection to iterate over.",
"name": "collection"
},
{
"type": {
"names": [
"function"
]
},
"description": "The function invoked per iteration.",
"name": "iteratee"
}
],
"returns": [
{
"type": {
"names": [
"Array",
"Object"
]
},
"description": "Returns `collection`."
}
],
"see": [
"forEachRight, forIn, forInRight, forOwn, forOwnRight"
],
"examples": [
"forEach([1, 2], value => console.log(value))\r// => Logs `1` then `2`.\r\rforEach({ 'a': 1, 'b': 2 }, (value, key) => console.log(key))\r// => Logs 'a' then 'b' (iteration order is not guaranteed)."
],
"name": "each",
"longname": "each",
"kind": "function",
"scope": "global",
"___id": "T000002R000309",
"___s": true,
"filepath": "forEach.js"
}