JavaScript object instance



Use built-in JavaScript object instances.

String (string) object

  • Returns the length of the string

  • Add style to the string

  • Returns the position where the specified text first appears in the string - indexOf() method

  • Looks for a specific character in the string, and if found, returns the character - match() method

  • Replace characters in a string - replace()

  • More string object examples in our JavaScript String Object Reference Manual.

Date (date) object

  • Use the Date() method to return today’s date and time

  • Use getTime() to calculate the number of milliseconds from 1970 to today

  • Use setFullYear() to set a specific date

  • Use toUTCString () Convert today's date (according to UTC) to a string

  • Use getDay() to display the day of the week, not just the number

  • Show a clock

  • For more Date object examples, see our JavaScript Date Object Reference.

Array (array) object

  • Create array

  • Merge two arrays - concat( )

  • Combine three arrays - concat()

  • Use the elements of the array to form a string - join()

  • Delete the last element of the array - pop()

  • Add a new element to the end of the array - push()

  • Reverse the order of elements in an array - reverse()

  • Delete the first element of the array - shift()

  • From Select elements in an array - slice()

  • Sort the array (ascending alphabetically) - sort()

  • Sort numerically (sort by Numerical order ascending) - sort()

  • Numerical sorting (numeric order descending) - sort()

  • at 2nd position in the array Add an element - splice()

  • Convert array to string -toString()

  • Add new element at the beginning of the array - unshift( )

  • For more examples of Array objects, see our JavaScript Array object reference.

Boolean (Boolean) object

  • Check logical value

  • More Boolean (Boolean) ) object object example, in our JavaScript Boolean Object Reference Manual.

Math (arithmetic) object

  • Use round() to round numbers

  • Use random() to return a random number between 0 and 1

  • Use max() to return the larger of two given numbers

  • Use min() to return the smaller of two given numbers

  • Celsius and Fahrenheit conversion

General

  • Use the for...in statement through object elements

  • More Math object examples are in our JavaScript Math Object Reference.