JavaScript Object
Examples
Using built-in JavaScript object instances.
String Object
- Return the length of a string
- Apply styles to a string
- Return the position of the first occurrence of specified text within a string - indexOf() method
- Search for a specific character in a string and return it if found - match() method
- Replace characters within a string - replace()
- More examples of the String object can be found in our JavaScript String Object Reference.
Date Object
- Use the Date() method to return today's date and time
- Use getTime() to calculate the milliseconds from 1970 to now
- Use setFullYear() to set a specific date
- Use toUTCString() to convert today's date (based on UTC) to a string
- Use getDay() to display the weekday, not just the number
- Display a clock
- More examples of the Date object can be found in our JavaScript Date Object Reference.
Array Object
- Create an array
- Merge two arrays - concat()
- Merge three arrays - concat()
- Join array elements into a string - join()
- Remove the last element from an array - pop()
- Add new elements to the end of an array - push()
- Reverse the order of elements in an array - reverse()
- Remove the first element from an array - shift()
- Select elements from an array - slice()
- Sort an array (alphabetically ascending) - sort()
- Sort numbers (numerically ascending) - sort()
- Sort numbers (numerically descending) - sort()
- Add an element at the second position in an array - splice()
- Convert an array to a string - toString()
- Add new elements to the beginning of an array - unshift()
- More examples of the Array object can be found in our JavaScript Array Object Reference.
Boolean Object
- Check logical values
- More examples of the Boolean object can be found in our JavaScript Boolean Object Reference.
Math Object
- Round numbers using round()
- Return a random number between 0 and 1 using random()
- Return the larger of two given numbers using max()
- Return the smaller of two given numbers using min()
- Celsius to Fahrenheit conversion
General
- Use for...in statements with object elements
- More Math object examples can be found in our JavaScript Math Object Reference.