Advertisement
GonMAX

Javascript CheatSheet

Nov 25th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* *******************************************************************************************
  2.  * GLOBAL OBJECTS > OBJECT
  3.  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
  4.  * ******************************************************************************************* */
  5.  
  6. // Global object: properties
  7. Object.length                                        // length is a property of a function object, and indicates how many arguments the function expects, i.e. the number of formal parameters. This number does not include the rest parameter. Has a value of 1.
  8. Object.prototype                                     // Represents the Object prototype object and allows to add new properties and methods to all objects of type Object.
  9.  
  10. // Methods of the Object constructor
  11. Object.assign(target, ...sources)                    // Copies the values of all enumerable own properties from one or more source objects to a target object. method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object
  12. Object.create(MyObject)                              // Creates a new object with the specified prototype object and properties. The object which should be the prototype of the newly-created object.
  13. Object.defineProperty(obj, prop, descriptor)         // Adds the named property described by a given descriptor to an object.
  14. Object.defineProperties(obj, props)                  // Adds the named properties described by the given descriptors to an object.
  15. Object.entries(obj)                                  // Returns an array containing all of the [key, value] pairs of a given object's own enumerable string properties.
  16. Object.freeze(obj)                                   // Freezes an object: other code can't delete or change any properties.
  17. Object.getOwnPropertyDescriptor(obj, prop)           // Returns a property descriptor for a named property on an object.
  18. Object.getOwnPropertyDescriptors(obj)                // Returns an object containing all own property descriptors for an object.
  19. Object.getOwnPropertyNames(obj)                      // Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.
  20. Object.getOwnPropertySymbols(obj)                    // Returns an array of all symbol properties found directly upon a given object.
  21. Object.getPrototypeOf(obj)                           // Returns the prototype of the specified object.
  22. Object.is(value1, value2);                           // Compares if two values are the same value. Equates all NaN values (which differs from both Abstract Equality Comparison and Strict Equality Comparison).
  23. Object.isExtensible(obj)                             // Determines if extending of an object is allowed.
  24. Object.isFrozen(obj)                                 // Determines if an object was frozen.
  25. Object.isSealed(obj)                                 // Determines if an object is sealed.
  26. Object.keys(obj)                                     // Returns an array containing the names of all of the given object's own enumerable string properties.
  27. Object.preventExtensions(obj)                        // Prevents any extensions of an object.
  28. Object.seal(obj)                                     // Prevents other code from deleting properties of an object.
  29. Object.setPrototypeOf(obj, prototype)                // Sets the prototype (i.e., the internal [[Prototype]] property).
  30. Object.values(obj)                                   // Returns an array containing the values that correspond to all of a given object's own enumerable string properties.
  31.  
  32. // Object instances and Object prototype object (Object.prototype.property or Object.prototype.method())
  33. // Properties
  34. obj.constructor                                      // Specifies the function that creates an object's prototype.
  35. obj.__proto__                                        // Points to the object which was used as prototype when the object was instantiated.
  36.  
  37. // Methods
  38. obj.hasOwnProperty(prop)                             // Returns a boolean indicating whether an object contains the specified property as a direct property of that object and not inherited through the prototype chain.
  39. prototypeObj.isPrototypeOf(object)                   // Returns a boolean indicating whether the object this method is called upon is in the prototype chain of the specified object.
  40. obj.propertyIsEnumerable(prop)                       // Returns a boolean indicating if the internal ECMAScript [[Enumerable]] attribute is set.
  41. obj.toLocaleString()                                 // Calls toString().
  42. obj.toString()                                       // Returns a string representation of the object.
  43. object.valueOf()                                     // Returns the primitive value of the specified object.
  44.  
  45. /* *******************************************************************************************
  46.  * GLOBAL OBJECTS > ARRAY
  47.  * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
  48.  * ******************************************************************************************* */
  49.  
  50. // Global object: properties
  51. Array.length                                         // Reflects the number of elements in an array.
  52. Array.prototype                                      // Represents the prototype for the Array constructor and allows to add new properties and methods to all Array objects.
  53.  
  54. // Global object: methods
  55. Array.from(arrayLike[, mapFn[, thisArg]])            // Creates a new Array instance from an array-like or iterable object.
  56. Array.isArray(obj)                                   // Returns true if a variable is an array, if not false.
  57. Array.of(element0[, element1[, ...[, elementN]]])    // Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.
  58.  
  59. // Instance: properties
  60. arr.length                                           // Reflects the number of elements in an array.
  61.  
  62. // Instance: mutator methods
  63. arr.copyWithin(target, start, end)                   // Copies a sequence of array elements within the array.
  64. arr.fill(value, start, end)                          // Fills all the elements of an array from a start index to an end index with a static value.
  65. arr.pop()                                            // Removes the last element from an array and returns that element.
  66. arr.push([element1[, ...[, elementN]]])              // Adds one or more elements to the end of an array and returns the new length of the array.
  67. arr.reverse()                                        // Reverses the order of the elements of an array in place — the first becomes the last, and the last becomes the first.
  68. arr.shift()                                          // Removes the first element from an array and returns that element.
  69. arr.sort()                                           // Sorts the elements of an array in place and returns the array.
  70. array.splice(start, deleteCount, item1, item2, ...)  // Adds and/or removes elements from an array.
  71. arr.unshift([element1[, ...[, elementN]]])           // Adds one or more elements to the front of an array and returns the new length of the array.
  72.  
  73. // Instance: accessor methods
  74. arr.concat(value1[, value2[, ...[, valueN]]])        // Returns a new array comprised of this array joined with other array(s) and/or value(s).
  75. arr.includes(searchElement, fromIndex)               // Determines whether an array contains a certain element, returning true or false as appropriate.
  76. arr.indexOf(searchElement[, fromIndex])              // Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
  77. arr.join(separator)                                  // Joins all elements of an array into a string.
  78. arr.lastIndexOf(searchElement, fromIndex)            // Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
  79. arr.slice(begin, end)                                // Extracts a section of an array and returns a new array.
  80. arr.toString()                                       // Returns a string representing the array and its elements. Overrides the Object.prototype.toString() method.
  81. arr.toLocaleString(locales, options)                 // Returns a localized string representing the array and its elements. Overrides the Object.prototype.toLocaleString() method.
  82.  
  83. // Instance: iteration methods
  84. arr.entries()                                        // Returns a new Array Iterator object that contains the key/value pairs for each index in the array.
  85. arr.every(callback[, thisArg])                       // Returns true if every element in this array satisfies the provided testing function.
  86. arr.filter(callback[, thisArg])                      // Creates a new array with all of the elements of this array for which the provided filtering function returns true.
  87. arr.find(callback[, thisArg])                        // Returns the found value in the array, if an element in the array satisfies the provided testing function or undefined if not found.
  88. arr.findIndex(callback[, thisArg])                   // Returns the found index in the array, if an element in the array satisfies the provided testing function or -1 if not found.
  89. arr.forEach(callback[, thisArg])                     // Calls a function for each element in the array.
  90. arr.keys()                                           // Returns a new Array Iterator that contains the keys for each index in the array.
  91. arr.map(callback[, initialValue])                    // Creates a new array with the results of calling a provided function on every element in this array.
  92. arr.reduce(callback[, initialValue])                 // Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
  93. arr.reduceRight(callback[, initialValue])            // Apply a function against an accumulator and each value of the array (from right-to-left) as to reduce it to a single value.
  94. arr.some(callback[, initialValue])                   // Returns true if at least one element in this array satisfies the provided testing function.
  95. arr.values()                                         // Returns a new Array Iterator object that contains the values for each index in the array.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement