Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. Creating Immutable Objects:
  2. Here are the following ways in which you can create immutable objects:
  3. a) Object.assign : for creating immutable object
  4. b) concat: for creating immutable array
  5. c) filter: The filter() method creates an array filled with all array elements that pass a test (provided as a function).
  6. var ages = [32, 33, 16, 40];
  7. function checkAdult(age) {
  8. return age >= 18;
  9. }
  10. function myFunction() {
  11. document.getElementById("demo").innerHTML = ages.filter(checkAdult);
  12. }
  13. d) map : The map() method creates a new array with the results of calling a function for every array element.
  14. The map() method calls the provided function once for each element in an array, in order
  15. e) reduce : The reduce() method reduces the array to a single value.
  16. Syntax : array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement