Presentation
topics
1.map
2.some
3.reduce
-
advance javascript Page 1 of 7
JavaScript Maps
The Map Object
A Map is a special kind of object that stores data
in key-value pairs — but with some powerful
advantages over normal objects.
advance javascript Page 2 of 7
How to Create a Map
You can create a JavaScript Map by:
Passing an Array to new Map()
Create a Map and use Map.set()
Example
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
advance javascript Page 3 of 7
JavaScript some()
Method
The some() method is used with arrays to check if
at least one element passes the given test
(condition).
It returns true if any element passes, otherwise
false
Syntax
array.some(callbackFunction(element, index, array), thisArg)
advance javascript Page 4 of 7
JavaScript reduce() Method
The reduce() method is used with arrays to
reduce all the elements into a single value (like
sum, product, object, string, etc.).
Syntax
array.reduce(callbackFunction(accumulator, currentValue, index,
array), initialValue)
advance javascript Page 5 of 7
Key Points
of reduce method
reduce() is very powerful – you can do sum, max, min,
group, flatten arrays, build objects, etc.
Always give an initial value to avoid errors on empty
arrays.
Returns a single value (number, object, array, anything
you decide).
advance javascript Page 6 of 7
THANK YOU!
advance javascript Page 7 of 7