Collect.js | avg() Method
The avg() method returns the average of all the items in a collection.
- Collect.js can be installed via NPM:
npm install --save collect.js
- You can also use CDN of collect.js
Parameters: The collect() takes one argument that is converted into the collection and then avg() function is applied on it, which can take element if you apply it on the collection of objects.
Return Value: Returns a number which is average of the collection.
Example 1: Here collect = require(‘collect.js’) is used to import the collect.js library into the file.
Example 2: Array of objects.