30 useful javascript methods to spice-up your coding

freakynit

Nitin Bansal

Posted on December 5, 2022

30 useful javascript methods to spice-up your coding
  1. Use the map() method to apply a function to each element in an array and create a new array with the results.
  2. Use the reduce() method to iterate over an array and create a single value from the elements.
  3. Use the filter() method to create a new array with only the elements that pass a certain condition.
  4. Use the sort() method to sort the elements in an array in ascending or descending order.
  5. Use the includes() method to check if a given element is present in an array.
  6. Use the find() method to find the first element in an array that matches a certain condition.
  7. Use the findIndex() method to find the index of the first element in an array that matches a certain condition.
  8. Use the Object.keys() method to get an array of the keys in an object.
  9. Use the Object.values() method to get an array of the values in an object.
  10. Use the Object.entries() method to get an array of key-value pairs in an object.
  11. Use the split() method to split a string into an array of substrings based on a given separator.
  12. Use the join() method to combine the elements of an array into a single string, separated by a specified separator.
  13. Use the toUpperCase() and toLowerCase() methods to convert the case of a string.
  14. Use the trim() method to remove leading and trailing whitespace from a string.
  15. Use the substr() method to extract a specified number of characters from a string, starting at a given index.
  16. Use the substring() method to extract a substring from a string, between two specified indices.
  17. Use the replace() method to replace one or more substrings in a string with a specified replacement.
  18. Use the indexOf() method to find the index of the first occurrence of a given substring in a string.
  19. Use the lastIndexOf() method to find the index of the last occurrence of a given substring in a string.
  20. Use the search() method to find the position of a regular expression match in a string.
  21. Use the match() method to find all matches of a regular expression in a string and return them as an array.
  22. Use the concat() method to combine two or more arrays into a single array.
  23. Use the slice() method to extract a portion of an array and create a new array with the extracted elements.
  24. Use the splice() method to add or remove elements from an array at a specified index.
  25. Use the reverse() method to reverse the order of the elements in an array.
  26. Use the push() method to add one or more elements to the end of an array.
  27. Use the pop() method to remove the last element from an array and return it.
  28. Use the unshift() method to add one or more elements to the beginning of an array.
  29. Use the shift() method to remove the first element from an array and return it.
  30. Use the Math.max() and Math.min() methods to find the maximum and minimum values in an array.

Note: This article is actually written by chatGPT (https://chat.openai.com/chat)🤩

💖 💪 🙅 🚩
freakynit
Nitin Bansal

Posted on December 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related