Overview of built-in JavaScript objects

Introduction

js this

Within JavaScript itself, there are built-in objects with their own properties and methods, intended to make programming easier.

  • Array
  • Math
  • Given
  • Function

In addition to the listed objects, there are also objects whose names are the same as the names of simple primitives (only with a capital letter):

  • String
  • Number

These objects are “equipped” with the methods needed to work with the corresponding data type and are intended to make working with primitive types easier. When the need arises for an operation on such a primitive type, the compiler automatically “wraps” the primitive type in its “counterpart” object, after which all methods of the built-in object are available.

In this article, I wanted to clearly gather in one place all methods and properties of objects embedded in javascript.

“String” as object

Methods that can be applied to a string object:

Methods of the String object

Object method Description charAt() Returns the character at the specified index (position) charCodeAt() Returns the Unicode of the character at the specified index concat() Joins two or more strings, and returns a new joined strings fromCharCode() Converts Unicode values to characters indexOf() Returns the position of the first found occurrence of a specified value in a string lastIndexOf() Returns the position of the last found occurrence of a specified value in a string localeCompare() Compares two strings in the current locale match() Searches a string for a match against a regular expression, and returns the matches replace() Searches a string for a specified value, or a regular expression, and returns a new string
where the specified values are replaced search() Searches a string for a specified value, or regular expression, and returns the position of the
match slice() Extracts a part of a string and returns a new string split() Splits a string into an array of substrings substr() Extracts the characters from a string, beginning at a specified start position, and through the
specified number of characters substring() Extracts the characters from a string, between two specified indices toLocaleLowerCase() Converts a string to lowercase letters, according to the host’s locale toLocaleUpperCase() Converts a string to uppercase letters, according to the host’s locale toLowerCase() Converts a string to lowercase letters toString() Returns the value of a String object toUpperCase() Converts a string to uppercase letters trim() Removes whitespace from both ends of a string valueOf() Returns the primitive value of a String object

Methods that wrap “string” in an HTML tag

The following methods return a string wrapped with an HTML tag (possibly some HTML attribute).

Object method Description anchor() Creates an anchor big() Displays a string using a big font blink() Displays a blinking string bold() Displays a string in bold fixed() Displays a string using a fixed-pitch font fontcolor() Displays a string using a specified color fontsize() Displays a string using a specified size italics() Displays a string in italics link() Displays a string as a hyperlink small() Displaysa string using a small font strike() Displays a string with a strikethrough sub() Displays a string as subscript text sup() Displays a string as superscript text

“Number” as object

Number is an object that has the following built-in methods:

Method Description of methods isFinite() Checks whether a value is a finite number isInteger() Checks whether a value is an integer isNaN() Checks whether a value is Number.NaN isSafeInteger() Checks whether a value is a safe integer toExponential(x) Converts a number into an exponential notation toFixed(x) Formats a number with x number of digits after the decimal point toPrecision(x) Formats a number to x length toString() Converts a number to a string valueOf() Returns the primitive value of a number

“Function” as object

Function is an object that has the following methods built in:

Method Description of methods Function.prototype.apply() This method gives the selected function the desired meaning of the “this” keyword, which immediately invokes the function. Through the first argument, it defines which object the keyword this will point to, while the other arguments passed through the array are the data needed by the initial function. Function.prototype.bind() Function.prototype.bind()This method gives the selected function the desired meaning of the “this” keyword. Through the first argument, it defines which object the keyword this will point to, while the other arguments, which are passed as a list of arguments, are the data needed by the initial function. Function.prototype.call() Function.prototype.call() This method gives the selected function the desired meaning of the “this” keyword, which immediately calls the function (eng. invoke). Through the first argument, it defines which object the keyword this will point to, while the other arguments, which are passed as a list of arguments, are the data needed by the initial function.

Array object

Methods that can be applied to the array object are as follows:

Method Description concat() Joins two or more arrays, and returns a copy of the joined arrays copyWithin() Copies array elements within the array, to and from specified positions every() Checks if every element in an array passes a test fill() Fill the elements in an array with a static value filter() Creates a new array with every element in an array that passes a test find() Returns the value of the first element in an array that passes a test findIndex() Returns the index of the first element in an array that passes a test forEach() Calls a function for each array element indexOf() Search the array for an element and returns its position isArray() Checks whether an object is an array join() Joins all elements of an array into a string lastIndexOf() Search the array for an element, starting at the end, and returns its position map() Creates a new array with the result of calling a function for each array element pop() Removes the last element of an array, and returns that element push() Adds new elements to the end of an array, and returns the new length reduce() Reduce the values of an array to a single value (going left-to-right) reduceRight() Reduce the values of an array to a single value (going right-to-left) reverse() Reverses the order of the elements in an array shift() Removes the first element of an array, and returns that element slice() Selects a part of an array, and returns the new array some() Checks if any of the elements in an array pass a test sort() Sorts the elements of an array splice() Adds/Removes elements from an array toString() Converts an array to a string, and returns the result unshift() Adds new elements to the beginning of an array, and returns the new length valueOf() Returns the primitive value of an array

Math object

Math object properties

The properties of the Math object return one of the known mathematical constants:

Object Property Description E Returns Euler’s number (approx. 2.718) LN2 Returns the natural logarithm of 2 (approx. 0.693) LN10 Returns the natural logarithm of 10 (approx. 2.302) LOG2E Returns the base-2 logarithm of E (approx. 1.442) LOG10E Returns the base-10 logarithm of E (approx. 0.434) PI Returns PI (approx. 3.14) SQRT1_2 Returns the square root of 1/2 (approx. 0.707) SQRT2 Returns the square root of 2 (approx. 1.414)

Math methods

Methods of the Math object take a number as an attribute and return the result of some mathematical operation on that number:

Object method Description abs(x) Returns the absolute value of x acos(x) Returns the arccosine of x, in radians asin(x) Returns the arcsine of x, in radians atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians atan2(y,x) Returns the arctangent of the quotient of its arguments ceil(x) Returns x, rounded upwards to the nearest integer cos(x) Returns the cosine of x (x is in radians) exp(x) Returns the value of Ex floor(x) Returns x, rounded downwards to the nearest integer log(x) Returns the natural logarithm (base E) of x max(x,y,z,…,n) Returns the number with the highest value min(x,y,z,…,n) Returns the number with the lowest value pow(x,y) Returns the value of x to the power of y random() Returns a random number between 0 and 1 round(x) Rounds x to the nearest integer sin(x) Returns the sine of x (x is in radians) sqrt(x) Returns the square root of x tan(x) Returns the tangent of an angle

Date object

Date is an object in javascript that is responsible for date and time, and the methods that can be applied to that object are as follows:

Object method Description getDate() Returns the day of the month (from 1-31) getDay() Returns the day of the week (from 0-6) getFullYear() Returns the year (four digits) getHours() Returns the hour (from 0-23) getMilliseconds() Returns the milliseconds (from 0-999) getMinutes() Returns the minutes (from 0-59) getMonth() Returns the month (from 0-11) getSeconds() Returns the seconds (from 0-59) getTime() Returns the number of milliseconds since midnight Jan 1, 1970 getTimezoneOffset() Returns the time difference between UTC time and local time, in minutes getUTCDate() Returns the day of the month, according to universal time (from 1-31) getUTCDay() Returns the day of the week, according to universal time (from 0-6) getUTCFullYear() Returns the year, according to universal time (four digits) getUTCHOurs() Returns the hour, according to universal time (from 0-23) getUTCMilliseconds() Returns the milliseconds, according to universal time (from 0-999) getUTCMinutes() Returns the minutes, according to universal time (from 0-59) getUTCMonth() Returns the month, according to universal time (from 0-11) getUTCSeconds() Returns the seconds, according to universal time (from 0-59) parse() Parses a date string and returns the number of milliseconds since January 1, 1970 setDate() Sets the day of the month of a date object setFullYear() Sets the year (four digits) of a date object setHours() Sets the hour of a date object setMilliseconds() Sets the milliseconds of a date object setMinutes() Set the minutes of a date object setMonth() Sets the month of a date object setSeconds() Sets the seconds of a date object setTime() Sets a date to a specified number of milliseconds after/before January 1, 1970 setUTCDate() Sets the day of the month of a date object, according to universal time setUTCFullYear() Sets the year of a date object, according to universal time (four digits) setUTCHOurs() Sets the hour of a date object, according to universal time setUTCMilliseconds() Sets the milliseconds of a date object, according to universal time setUTCMinutes() Set the minutes of a date object, according to universal time setUTCMonth() Sets the month of a date object, according to universal time setUTCSeconds() Set the seconds of a date object, according to universal time toDateString() Converts the date portion of a Date object into a readable string toISOString() Returns the date as a string, using the ISO standard toJSON() Returns the date as a string, formatted as a JSON date toLocaleDateString() Returns the date portion of a Date object as a string, using locale conventions toLocaleTimeString() Returns the time portion of a Date object as a string, using local conventions toLocaleString() Converts a Date object to a string, using locale conventions toString() Converts a Date object to a string toTimeString() Converts the time portion of a Date object to a string toUTCString() Converts a Date object to a string, according to universal time UTC() Returns the number of milliseconds in a date since midnight of January 1, 1970, according to
UTC time valueOf() Returns the primitive value of a Date object