20 Best Javascript Snippets .

Priti Jha
Jul 10, 2023

--

Get current date and time :

const dateTime = new Date();

Merge two array :

 const newArray = this.array1.concat(array2);

Removes duplicates from array:

const uniqueArray = [...new set(array)] 

Check if a variable is an array:

Array.isArray(variable);

Reverse an array:

array.reverse();

Convert string to number:

const newnumber = parseInt(string1);

Sort an array in ascending order:

array.sort((a,b)=> a-b);

Generate a random number between two values:

const randomNumber = Math.floor(Math.random()*(max-min+1))+min;)

Copy text to clipboard

--

--

Priti Jha

Senior front-end developer writing about Angular 8 , Ionic Framework ,Javascript, HTML, Css and all front end technology.