Learn how to get the maximum of numbers. max function in the Math object can be used to find the maximum of multiple numbers and array. Math.max(1,2); //2 Math.max(1,2,3); //3 If any one of the argument passed cannot be converted to number then it returns NaN Math.max(‘1’, 0); //1 Math.max(‘one’, 1); // NaN Math.max(1, 2, …
Tag Archives: Javascript tips
Flatten an array in javascript
Learn how to convert a multi-dimensional array into single dimension array in javascript We can flatten an array to single dimension array using Array.flat(depth) method. But if we have multi-dimensional array then we need to find the depth of the Array, instead of finding depth we can solve the problem in two ways we can …
Removing space in string in Javascript
Learn how to remove space in string. If you want to remove all the space in the string then , you can use replace method var name = “Javascript jeep “; name.replace(/s/g,”); // Javascriptjeep s –> spaceg –> replace globally We can also replace the space with ‘-‘ var name = “Javascript jeep “; name.replace(/s/g,’-‘); // …
Misunderstanding on parsing Boolean
Learn about how to parse boolean in Javascript. Creating a boolean value using Boolean constructor var b = new Boolean(); b is an object which have the value false in it. But the problem here is most of the beginner think as we can use directly in if , but it results to misunderstanding if(b) { …
How to convert 24 hours format to 12 hours in Javascript.
Convert the 24 hours format time to 12 hours formatted time. You can get the time by , var dt = new Date(); var hours = dt.getHours(); // gives the value in 24 hours format var minutes = dt.getMinutes() ; var finalTime = “Time – ” + hours + “:” + minutes; finalTime // final time …
Continue reading “How to convert 24 hours format to 12 hours in Javascript.”
Difference between String primitives and String object.
Learn about, in what way the string primitive and string objects are different in javascript. We can create string in three ways, 1. var a = “first way”; // we can also use single quotes 2. var b = String(“second way”); 3. var c = new String(“third way”); // also we can create using 4. …
Continue reading “Difference between String primitives and String object.”
The Set Data Structure in Javascript
Learn about how to use and when to use Set in JavaScript. The Set object allows you to create a collection of unique values(each value can occur only once). Set can contain any type of value (primitives or object reference). Set stores elements in the insertion order. The Set doesn’t contain’s keys 🔑 like a …
A Simple Introduction to the ES6 Map Data Structure in JavaScript
A Map is a collection of key🔑 — value pairs, similar to an object. It stores the key🔑 — value pairs in the insertion order. We can create a Map by passing an iterable object whose elements are in the form of key🔑 — value (Eg. [ [1,”one”], [2,”two”] ] ), or you can create an empty Map, then insert entries. …
Continue reading “A Simple Introduction to the ES6 Map Data Structure in JavaScript”
Different ways and correct way to delete an array .
Learn about what is the right way to delete an array in Javascript. Let’s create an Array let array = [1,2,3,4,5]; First way to delete an array is , referencing to a new empty array array = []; Let’s look an example var array1 = [1,2,3,4,5]; var array2 = array1; array1[0] = 100; array2[0]; //100 because …
Continue reading “Different ways and correct way to delete an array .”
The Complete Reference for JavaScript Arrays
Learn all the methods available to Arrays in Javascript. Different ways of creating an array var array = []; var array = Array(); var array = Array(3); // array of length 3 var array = new Array() var array = new Array(3) // array of length 3 1. Array.from() The Array.from method creates a new shallow …
Continue reading “The Complete Reference for JavaScript Arrays”