Table of contents
  1. Generate a random string
  2. Generate a random string of a given length
  3. Copy content to the clipboard
  4. Clear all cookies
  5. Get the selected text
  6. Scroll to the top of the page
  7. Check whether the user has scrolled to the bottom of a page
  8. Find out whether the current tab is active
  9. Redirect the user to a URL
  10. Open the browser print box
  11. Generate a random boolean value
  12. Generate a random number between two values
  13. Check if a given number is an integer
  14. Remove duplicate values in an array
  15. [Get the unique values in an array]
  16. Check if a variable is an array
  17. Check if the date is Weekend
  18. Calculate number of days between two dates
  19. Capitalize a String
  20. Get the day of the year from a date
  21. Check if a string is a palindrome
  22. Get the first n elements of an array
  23. Get the last n elements of an array
  24. Remove all vowels from a string
  25. Check if a string contains a substring
  26. Get the current time in hh:mm:ss format
  27. Check if an object is empty
  28. not empty
  29. Get the current date and time
  30. Reverse a String
  31. Sort Arrays
  32. Extract the Domain name from an email
  33. Flatten an Nested Array
  34. Generates a Random Color in Hexadecimal Format
  35. Checks if a given value is a valid Hexadecimal Color Code
  36. Get the current time in a specific timezone
  37. Convert a String to kebab-case
  38. Shuffle an Array
  39. Shuffle an array using the Fisher-Yates (Knuth) Shuffle algorithm
  40. Convert RGB color code to valid Hexadecimal color code
  41. Truncate a number to a fixed decimal point
  42. Remove falsy values from Array
  43. A function that toggles a boolean value
  44. A concise way to swap the values of two variables using array
  45. The concat() method returns a new array containing elements from both arr1 and arr2.
  46. The spread operator is concise and visually clear. It takes the elements from both arrays and creates a new array.
  47. This approach modifies arr1 in place by using push() along with apply() to add elements from arr2.
  48. The spread operator is used to expand the elements of arr2 into individual arguments for the push() method.
  49. The spread operator is used to expand the elements of arr2 as arguments to the concat() method.
  50. JavaScript primitives Truncate string at the end
  51. The function will truncate the input string to the specified length and add an ellipsis (...) at the end if the string is longer than the specified length.
  52. The function is to truncate the input string while keeping the specified number of characters from the start and end, and adding an ellipsis (...) in the middle.
  53. Get the value of a browser cookie by its name
  54. from a JavaScript Date object.
  55. Check if a number is even or odd
  56. Converts the first character of a given string to lowercase
  57. Repeats a given string a specific number of times
  58. Check if the code is running in Node.js
  59. Check if the code is running in the browser
  60. Get all siblings of a given element
  61. Go back to the previous page using the history object
  62. Function to get the largest element in an array
  63. Function to get the smallest element in an array
  64. Function to toggle the visibility of an HTML element
  65. Function to remove HTML tags from a given String
  66. Define a function to check if a given value is a DOM Element
  67. Define a function to check if a given string is a valid URL
  68. Check if a string starts with a given prefix
  69. Check if a string ends with a given suffix
  70. Check if a value is an object
  71. Check if a value is a function
  72. Check if a value is a Promise
  73. Check if an HTML element is entirely within the viewport




Generate a random string

const randomString = () => Math.random().toString(36).slice(2);

Generate a random string of a given length

const randomString = (length = 10) => {
    let result = "";
    while (result.length < length) {
        result += Math.random().toString(36).slice(2);
    }
    returr;
    result.slice(0, length);
};

Copy content to the clipboard

const copyToClipboard = (text) => navigator.clipboard.writeText(text);
copyToClipboard("Hello World");

Clear all cookies

const clearcookies = document.cookie
                             .split(";")
                             .forEach((cookie) => (document.cookie = cookie.replace(/=.*/, `=;expires=$(new Date(0). toUTCString()} ;path=/`,)),);

Get the selected text

const getSelectedText = () => window.getSelection().toString();
getSelectedText();

Scroll to the top of the page

const goToTop = () => window.scrollTo(0, 0);
goToTop();

Check whether the user has scrolled to the bottom of a page

const scrolledToBottom = () => document.documentElement.clientHeight + window.scrollY >= document.documentElement.scrollHeight

Find out whether the current tab is active

const isTabInView = () => !document.hidden

Redirect the user to a URL

const redirect = url => location.href = url
redirect("https://www.google.com/")

Open the browser print box

const showPrintDialog = ()
window.print()

Generate a random boolean value

// Returns a random boolean value (true or false)
const randomBoolean = () => Math.random() >= 0.5;
randomBoolean();

Generate a random number between two values

Check if a given number is an integer

Remove duplicate values in an array

[Get the unique values in an array]

Check if a variable is an array

Check if the date is Weekend

Calculate number of days between two dates

Capitalize a String

Get the day of the year from a date

Check if a string is a palindrome

Get the first n elements of an array

Get the last n elements of an array

Remove all vowels from a string

Check if a string contains a substring

Get the current time in hh:mm:ss format

Check if an object is empty

not empty


Get the current date and time

Reverse a String

Sort Arrays

Extract the Domain name from an email

Flatten an Nested Array

Generates a Random Color in Hexadecimal Format

Checks if a given value is a valid Hexadecimal Color Code

Get the current time in a specific timezone

Convert a String to kebab-case

Shuffle an Array

Shuffle an array using the Fisher-Yates (Knuth) Shuffle algorithm

Convert RGB color code to valid Hexadecimal color code

Truncate a number to a fixed decimal point

Remove falsy values from Array

A function that toggles a boolean value

A concise way to swap the values of two variables using array

The concat() method returns a new array containing elements from both arr1 and arr2.

The spread operator is concise and visually clear. It takes the elements from both arrays and creates a new array.

This approach modifies arr1 in place by using push() along with apply() to add elements from arr2.

The spread operator is used to expand the elements of arr2 into individual arguments for the push() method.

The spread operator is used to expand the elements of arr2 as arguments to the concat() method.

JavaScript primitives Truncate string at the end

The function will truncate the input string to the specified length and add an ellipsis (...) at the end if the string is longer than the specified length.

The function is to truncate the input string while keeping the specified number of characters from the start and end, and adding an ellipsis (...) in the middle.

Get the value of a browser cookie by its name

from a JavaScript Date object.

Check if a number is even or odd

Converts the first character of a given string to lowercase

Repeats a given string a specific number of times

Check if the code is running in Node.js

Check if the code is running in the browser

Get all siblings of a given element

Go back to the previous page using the history object

Function to get the largest element in an array

Function to get the smallest element in an array

Function to toggle the visibility of an HTML element

Function to remove HTML tags from a given String

Define a function to check if a given value is a DOM Element

Define a function to check if a given string is a valid URL

Check if a string starts with a given prefix

Check if a string ends with a given suffix

Check if a value is an object

Check if a value is a function

Check if a value is a Promise

Check if an HTML element is entirely within the viewport