Find the max value in an array
Remove duplicates from an array
Generate a random number between 1 and 100
Math . floor ( Math . random ( ) * 100 ) + 1
Check if a string is a valid number
! isNaN ( parseFloat ( string ) )
Get the current date and time
Check if a variable is an array
Check if a variable is an object
typeof variable === "object"
Convert an array to a string
Check if a variable is a function
typeof variable === "function"
Convert an object to an array
Count the occurrences of an element in an array
array . filter ( x => x === element ) . length
Create a new object with a dynamic key and value
Check if a string is a palindrome
string === string . split ( "" ) . reverse ( ) . join ( "" )
Create a new array with unique values
Get the current timestamp
Check if a variable is null
Check if a variable is undefined
typeof variable === "undefined"
Create a new array with no duplicates
Check if an array is empty
Create a new array with a specified range of numbers
Array . from ( { length : n } , ( _ , i ) => i )
Delete a specific item from an array
arr . splice ( arr . indexOf ( item_to_delete ) , 1 )
const shuffleArray = ( arr ) => arr . sort ( ( ) => Math . random ( ) - 0.5 ) ;
const copyToClipboard = ( text ) => navigator . clipboard ?. writeText && navigator . clipboard . writeText ( text ) ;
const getUnique = ( arr ) => [ ...new Set ( arr ) ] ;
const isDarkMode = ( ) => window . matchMedia && window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ;
const scrollToTop = ( element ) => element . scrollIntoView ( { behavior : "smooth" , block : "start" } ) ;
const scrollToBottom = ( element ) => element . scrollIntoView ( { behavior : "smooth" , block : "end" } ) ;
const generateRandomHexColor = ( ) => `#${ Math . floor ( Math . random ( ) * 0xffffff ) . toString ( 16 ) } ` ;
Round Decimals to a Certain Number of Decimal Places
const round = ( n , d ) => Number ( Math . round ( n + "e" + d ) + "e-" + d )
const capitalize = str => str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 )
Toggle Display of an Element
const toggle = element => element . style . display = ( element . style . display === "none" ? "block" : "none" )
const clearCookies = document . cookie . split ( ';' ) . forEach ( cookie => document . cookie = cookie . replace ( / ^ +/ , '' ) . replace ( / =.*/ , `=;expires=${ new Date ( 0 ) . toUTCString ( ) } ;path=/` ) ) ;
const stripHtml = html => ( new DOMParser ( ) . parseFromString ( html , 'text/html' ) ) . body . textContent || ''