How to insert element based on index in an array.

Learn how to insert an element in specified index of the array in Javascript. The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in-place(in original array). The splice method will take three argument → start , deleteCount(optional), items to add (optional) . In the above program we …

String methods : startsWith in Javascript.

Learn about the startsWith method of string object in Javascript. The startsWith() method returns true if the given characters are found at the beginning of the string, otherwise, false. If you want this method to be non case-sensitive then we can write a custom function We can also specify the position from which to begin …

Enabling full screen in Javascript.

Learn how to enable full screen using Javascript. We can use requestFullscreen() method on any element to make the element as full screen. requestFullscreen() method makes an asynchronous request to make the element be displayed in full-screen mode. We can check if any other element is already in fullscreen mode by using document.fullscreenElement . To exit …

Selecting , clearing and focusing on input in Javascript.

Learn how to select text, focus and clear the text in input box in Javascript. input.value = “” → this will make the input value to empty string. input.focus() → this method will set focus on the input box. input.select() → this will select the text in the input box. If you find this helpful …

Css selector for element which have numbers as class name.

Learn how to select the element which has the class name starting with number. HTML5 supports numbers as id and class name , but css selector have some rules , A valid name should start with a letter (a-z)[A-Z] , an underscore (_), or a hyphen (-) which is followed by any numbers, hyphens, underscores, letters. A name …

Remove All children đź‘¶ of the node in Javascript.

Learn how to delete all the nodes inside a div or any node in Javascript. You can do it in three ways 1 . Set the node innerHTML as empty-string(“”). var node = document.getElementById(‘parent’); node.innerHTML = “”; This method removes all the text and nodes inside the parent node. If you need to delete only the …

Understanding weirdness of the “!” bang operator in JavaScript

There are some things we don’t know about how the ! operator works in Javascript. Basics The ! is a logical operator that will convert a value to its opposite boolean. Since JavaScript will coerce values, it will “convert” a value to its truthy/falsey form and return the opposite boolean value. When we perform the ! operation on …

Getting max of numbers in Javascript.

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, …

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 …

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) { …

Design a site like this with WordPress.com
Get started