Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Creating Immutable Objects:
- Here are the following ways in which you can create immutable objects:
- a) Object.assign : for creating immutable object
- b) concat: for creating immutable array
- c) filter: The filter() method creates an array filled with all array elements that pass a test (provided as a function).
- var ages = [32, 33, 16, 40];
- function checkAdult(age) {
- return age >= 18;
- }
- function myFunction() {
- document.getElementById("demo").innerHTML = ages.filter(checkAdult);
- }
- d) map : The map() method creates a new array with the results of calling a function for every array element.
- The map() method calls the provided function once for each element in an array, in order
- e) reduce : The reduce() method reduces the array to a single value.
- Syntax : array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement