Return to site

JAVASCRIPT REDUCE METHOD EXPLAINED

October 7, 2021

reduce method in JavaScript is used to reduce the array to a single value.

It takes a callback function which takes four parameters (accumulator, currentValue, index, array), but mostly we use the first two.

Examples

๐Ÿงต๐Ÿ‘‡

๐Ÿ. ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž ๐ฌ๐ฎ๐ฆ ๐จ๐Ÿ ๐š๐ฅ๐ฅ ๐ญ๐ก๐ž ๐ž๐ฅ๐ž๐ฆ๐ž๐ง๐ญ๐ฌ ๐ข๐ง ๐š๐ง ๐š๐ซ๐ซ๐š๐ฒ

๐Ÿ. ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž ๐ญ๐จ๐ญ๐š๐ฅ ๐ง๐ฎ๐ฆ๐›๐ž๐ซ ๐จ๐Ÿ ๐Ÿ๐ซ๐ฎ๐ข๐ญ๐ฌ ๐ข๐ง ๐ญ๐ก๐ž ๐š๐ซ๐ซ๐š๐ฒ

๐Ÿ‘. ๐†๐ซ๐จ๐ฎ๐ฉ ๐ฌ๐ญ๐ฎ๐๐ž๐ง๐ญ๐ฌ ๐›๐ฒ ๐œ๐ฅ๐š๐ฌ๐ฌ๐ง๐š๐ฆ๐ž