The ** operator returns the result of the first variable to the power of the second variable. That is, Math.pow(a,b). Photo by Crissy Jarvis on Unsplash var a = 2;var b = 5; a ** b; // 32 Math.pow(a, b); // 32 If we do like a ** b ** c , then the operation is computed …
Category Archives: Uncategorized
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 …
Continue reading “How to insert element based on index in an array.”
Create beautiful boxes using the outline CSS property
outline is a line outside the border of a container. Let’s create a simple rectangle and apply an outline and see how cool 😎 it is. The syntx for ourline is outline: size type color; The above code will create a beautiful frame 🖼 . The available values are outline: auto → Permits the user agent …
Continue reading “Create beautiful boxes using the outline CSS property”
Three different ways to loop through JavaScript objects
Learn how to loop through objects in Javascript. var object = { name : “Javascript Jeep”, status : “😎”, icons : “🚗” } Using for..in With ES6, we can use Object.entries to loop through each entry of the object. The Object.entries method returns an array of [key, value]. We can also use Object.keys which will …
Continue reading “Three different ways to loop through JavaScript objects”
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 …
Continue reading “String methods : startsWith in Javascript.”
Creating notification bell 🔔 in javascript.
Learn how to create notification in Javascript. The Notification API allows you to create notification on the web page. To create notification first we need to change the notification default settings. Here change the Notification block to allow. So the notification will be displayed . To check for notification support in the browser , To check thr …
Continue reading “Creating notification bell 🔔 in javascript.”
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 …
Generate random numbers in JavaScript using Crypto, without Math.rand()
Learn how to get a random number without using Math.rand() The Crypto.getRandomValues() method lets you get cryptographically strong random values. Syntax: getRandomValues(typedArray) Argument: typedArray → Is an integer-based TypedArray, which can be an Int8Array or an Uint8Array or an Int16Array or a Uint16Array or an Int32Array or a Uint32Array. All elements in the array are …
Continue reading “Generate random numbers in JavaScript using Crypto, without Math.rand()”
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 …
Continue reading “Selecting , clearing and focusing on input in Javascript.”
Remove duplicate values of the array in Javascript.
Learn how to remove the duplicate values in the array Simple Way is using Set (which only contains unique value). var array = [1,2,3,4,1,2,3]; var unique = [… new Set(array)] ; //or var unique = Array.from (new Set(array) ); Another way is var elements = [1,2,3,4,1,2,3]; var uniqueArray = elements.filter(function(element, currentIndex) { return elements.indexOf(element) == …
Continue reading “Remove duplicate values of the array in Javascript.”