- Array – An array is a collection of elements that can be accessed by index.
- Date – A date object represents a specific point in time.
- Math – The Math object provides a number of mathematical functions, such as sin(), cos(), and sqrt().
- String – A string object represents a sequence of characters.
- Boolean – The Boolean constructor creates a Boolean object.
- Function – The Function constructor creates a function object.
- Number – The Number constructor creates a Number object.
- Symbol – The Symbol constructor creates a Symbol object.
var numbers = [1, 2, 3, 4, 5];
var average = numbers.reduce((a, b) => a + b) / numbers.length;
console.log(average); // 3
This code uses the Array object’s reduce() method to calculate the average of the numbers in the numbers array. The reduce() method takes two arguments: a starting value and a function. The function is called once for each element in the array, and the starting value is used as the argument to the function the first time it is called. The function returns the value that is used as the argument to the function the next time it is called. In this case, the function simply adds the current element of the array to the starting value. The reduce() method returns the final value after all of the elements of the array have been processed.