Advertisement
stanevplamen

JS methods and ops

Sep 21st, 2022 (edited)
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.19 KB | Software | 0 0
  1. // array ops
  2. var arr = [];
  3.  
  4. arr.push();
  5. arr.unshift();
  6.  
  7. arr.pop(); // stack
  8. arr.shift(); // queue
  9.  
  10. //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
  11. arr = arr.concat(arr2); // combine
  12. arr.slice(1);
  13. arr.splice(1,0,item);
  14.  
  15. arr.join(“‘”);
  16. //
  17.  
  18. arr.includes() // true
  19. arr.indexOf();
  20.  
  21. arr.reverse();
  22.  
  23. arr.sort();
  24. arr.sort(compare);
  25.  
  26. function compare(a,b) {
  27.     if a.prop < b.prop return -1
  28.     else if b.prop < a.prop return 1
  29.     else return 0
  30. }
  31.  
  32. function compare(a,b) {
  33.     return a -b
  34. }
  35.  
  36. var d2m3x = [
  37.     [1,2,3],
  38.     [4,5,6],
  39.     [7,8,9]
  40. ];
  41.  
  42. var d3m3x = [
  43.     [
  44.         [1,2,3],
  45.         [4,5,6],
  46.         [7,8,9]
  47. ],
  48.     [
  49.         [1,2,3],
  50.         [4,5,6],
  51.         [7,8,9]
  52. ],
  53.     [
  54.         [1,2,3],
  55.         [4,5,6],
  56.         [7,8,9]
  57. ]
  58. ];
  59.  
  60. // string ops
  61.  
  62. slice()
  63. substr()
  64. replace();
  65. replaceAll();
  66. concat();
  67. trim();
  68. indexOf();
  69. charAt();
  70. split();
  71.  
  72.  
  73. includes();
  74. startsWith();
  75.  
  76. toLowerCase()
  77. toUpperCase();
  78.  
  79. // match ops
  80.  
  81. +
  82. -
  83. *
  84. /
  85. %
  86. ** x**y == Math.pow(x,y)
  87. Math.sqrt(x)
  88. Math.pow(25, 1/2) = 5
  89. Math.pow(n, 1/root)
  90. ++
  91.  
  92. toFixed(2); // two decimal places
  93. Number(3); // parse to numb
  94. parseInt();
  95. parseFloat();
  96.  
  97. Math.round();
  98. Math.ceil();
  99. Math.floor();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement