Front End Technology Articles

Page 384 of 652

How to get the protocol and page path of the current web page in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 789 Views

In JavaScript, you can retrieve both the protocol (like https:// or http://) and the page path of the current webpage using the window.location object and URL constructor. These properties are essential for web development tasks like URL manipulation and navigation. Getting the Protocol The protocol specifies the data transfer method used by the URL. Use window.location.protocol or URL.protocol to retrieve it. Syntax protocol = window.location.protocol; // or protocol = new URL(url).protocol; Using window.location.protocol Protocol Example ...

Read More

Replacing all special characters with their ASCII value in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

We are required to write a JavaScript function that takes in a string that might contain some special characters. The function should return a new string with all special characters replaced with their corresponding ASCII value. Understanding Special Characters Special characters are symbols that are not letters, numbers, or spaces. Examples include !, @, #, $, etc. Each character has a unique ASCII code that can be retrieved using the charCodeAt() method. Example Following is the code: const str = 'Th!s !s @ str!ng th@t cont@!ns some special characters!!'; const specialToASCII = str ...

Read More

How to return an array whose elements are the enumerable property values of an object in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 304 Views

We can use various methods to get values and keys from an object, but those methods will not return the values as an array, which is very useful in many cases. JavaScript provides the Object.values() method to get an array whose elements are the enumerable property values of an object. Syntax Object.values(obj); This method takes an object as an argument and returns an array whose elements are the property values of the object. Parameters obj: The object whose enumerable property values are to be returned. Return Value An array containing the ...

Read More

Inserting element at falsy index in an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 246 Views

We are required to write an Array function, let's say, pushAtFalsy() The function should take in an array and an element. It should insert the element at the first falsy index it finds in the array. If there are no empty spaces, the element should be inserted at the last of the array. We will first search for the index of empty position and then replace the value there with the value we are provided with. Understanding Falsy Values In JavaScript, falsy values include: null, undefined, false, 0, "" (empty string), and NaN. However, since 0 ...

Read More

How to get the pixel depth and color depth of a screen in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 619 Views

The JavaScript window object provides methods to get screen display information through the screen object. Two important properties are screen.colorDepth and screen.pixelDepth which return the color depth and pixel depth of the browser screen respectively. Color Depth The screen.colorDepth property returns the number of bits used to display one color on the screen. Modern computers typically use 24-bit or 32-bit hardware for color resolution, where: 24-bit color: Supports 16.7 million colors (True Color) 32-bit color: Includes an alpha channel for transparency Syntax screen.colorDepth Example ...

Read More

Array of adjacent element's average - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 324 Views

Let's say, we have an array of numbers: const arr = [3, 5, 7, 8, 3, 5, 7, 4, 2, 8, 4, 2, 1]; We are required to write a function that returns an array with the average of the corresponding element and its predecessor. For the first element, as there are no predecessors, so that very element should be returned. Let's write the code for this function, we will use the Array.prototype.map() function to solve this problem: Example const arr = [3, 5, 7, 8, 3, 5, 7, 4, 2, 8, ...

Read More

How to find the inner height and inner width of a browser window in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 701 Views

In this article we are going to learn how to find the inner height and inner width of a browser window using JavaScript. JavaScript defines window object methods and properties. The properties include inner height and inner width, which helps us to calculate the height and width of a window's content area excluding scrollbars, toolbars, and other browser UI elements. There are two main approaches to calculate the inner height and inner width of a window: Using innerHeight and innerWidth properties − The window.innerHeight and window.innerWidth properties return the viewport dimensions including padding ...

Read More

What is the importance of '/g' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 674 Views

The /g flag in JavaScript regular expressions stands for "global" and is essential for finding all matches in a string rather than stopping after the first match. Without this flag, regex methods will only find the first occurrence of a pattern. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created in two ways: Literal notation: Uses forward slashes with optional flags after the second slash (e.g., /pattern/g). This is preferred when the pattern remains constant. Constructor function: Uses new RegExp("pattern", "flags"). This is useful when the pattern ...

Read More

Build maximum array based on a 2-D array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 168 Views

Let's say, we have an array of arrays of Numbers like below − const arr = [ [1, 16, 34, 48], [6, 66, 2, 98], [43, 8, 65, 43], [32, 98, 76, 83], [65, 89, 32, 4], ]; We are required to write a function that maps over this array of arrays and returns an array that contains the maximum (greatest) element from each subarray. So, for the above array, the output should be − [48, 98, 65, 98, 89] Using ...

Read More

What is the importance of '/i' flag in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 548 Views

The /i flag in JavaScript is a regular expression modifier that enables case-insensitive pattern matching. By default, regular expressions are case-sensitive, meaning they distinguish between uppercase and lowercase letters. Understanding Regular Expressions Regular expressions are patterns used to match character combinations in strings. They can be created using two methods: Literal notation: Uses slashes to enclose the pattern (/pattern/flags). Best for static patterns that won't change during execution. Constructor method: Uses the RegExp constructor (new RegExp("pattern", "flags")). Ideal when the pattern needs to be dynamic or constructed at runtime. ...

Read More
Showing 3831–3840 of 6,519 articles
« Prev 1 382 383 384 385 386 652 Next »
Advertisements