DEV Community

Robert Lynch
Robert Lynch

Posted on

Most commonly used JavaScript methods

There are many commonly used JavaScript methods, as the language has a large and comprehensive standard library. Some of the most commonly used methods include:


console.log()
Enter fullscreen mode Exit fullscreen mode

This method is used to log messages to the console. It is often used for debugging and testing purposes.

document.getElementById()
Enter fullscreen mode Exit fullscreen mode

This method is used to retrieve an element from the DOM (Document Object Model) by its unique ID.

array.forEach()
Enter fullscreen mode Exit fullscreen mode

This method is used to iterate over the elements of an array and perform a specific action on each element.

string.split()
Enter fullscreen mode Exit fullscreen mode

This method is used to split a string into an array of substrings based on a specified delimiter.

string.replace()
Enter fullscreen mode Exit fullscreen mode

This method is used to replace a specified value in a string with another value.

Math.random()
Enter fullscreen mode Exit fullscreen mode

This method is used to generate a random number between 0 (inclusive) and 1 (exclusive).

array.sort()
Enter fullscreen mode Exit fullscreen mode

This method is used to sort the elements of an array in place, according to their natural sort order or a custom sort function.

array.map()
Enter fullscreen mode Exit fullscreen mode

This method is used to create a new array by performing a specific action on each element of the original array.

object.hasOwnProperty()
Enter fullscreen mode Exit fullscreen mode

This method is used to check if an object has a specific property defined directly on it (as opposed to inherited from its prototype).

string.trim()
Enter fullscreen mode Exit fullscreen mode

This method is used to remove leading and trailing white space from a string.

These are just a few examples, but there are many other commonly used methods in the JavaScript language.

For a complete list check out the Mozilla Developers Network

Top comments (0)