Web Development Articles

Page 424 of 801

JavaScript - know the value of GET parameters from URL

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 287 Views

To extract GET parameters from a URL in JavaScript, you can use the built-in URL and URLSearchParams APIs. These provide a clean way to parse query strings from URLs. Using URL and URLSearchParams The URL constructor creates a URL object, and its searchParams property gives access to query parameters: GET Parameters Example body { ...

Read More

Group array by equal values JavaScript

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

Let's say, we have an array of string/number literals that contains some duplicate values like this: const array = ['day', 'night', 'afternoon', 'night', 'noon', 'night', 'noon', 'day', 'afternoon', 'day', 'night']; We are required to write a function groupSimilar() that takes in this array and returns a new array where all the repeating entries are grouped together in a subarray as the first element and their total count in the original array as the second element. So, for this example, the output should be: [ [ 'day', 3 ], ...

Read More

JavaScript lastIndex Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 169 Views

The lastIndex property in JavaScript is used with regular expressions to track the position where the next search will begin. It only works with the global (g) flag and automatically updates after each match. Syntax regexObject.lastIndex How lastIndex Works The lastIndex property starts at 0 and updates to the position after each match when using exec() or test() with the global flag. JavaScript lastIndex Property Finding Multiple Matches with lastIndex let text = "The king bought an expensive ring."; let regex ...

Read More

Form Object from string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

We are required to write a function that takes in a string as the first and the only argument and constructs an object with its keys based on the unique characters of the string and value of each key being defaulted to 0. For example − // if the input string is: const str = 'hello world!'; // then the output should be: const obj = {"h": 0, "e": 0, "l": 0, "o": 0, " ": 0, "w": 0, "r": 0, "d": 0, "!": 0}; So, let's write the code for this function − ...

Read More

JavaScript Let

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 221 Views

The JavaScript let keyword, introduced in ES6 (2015), allows us to declare block-scoped variables. Unlike var, variables declared with let are only accessible within the block where they are defined. Block Scope with let Variables declared with let are confined to their block scope and cannot be accessed outside of it. JavaScript Let Example JavaScript Let Block Scope Test Block Scope ...

Read More

Check for Power of two in JavaScript

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

We need to write a function, isPowerOfTwo(), that takes a positive number and returns a boolean based on whether the number is a power of 2. For example: isPowerOfTwo(3) // false (3 is not a power of 2) isPowerOfTwo(32) // true (32 = 2^5) isPowerOfTwo(2048) // true (2048 = 2^11) isPowerOfTwo(256) // true (256 = 2^8) isPowerOfTwo(22) // false (22 is not a power of 2) Method 1: Using Recursive Division This approach recursively divides the number by 2 until it reaches 1 (power of 2) ...

Read More

JavaScript Location protocol Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 252 Views

The location.protocol property in JavaScript returns the protocol scheme of the current URL, including the colon (:). This property is useful for determining whether a page is loaded over HTTP, HTTPS, or other protocols. Syntax location.protocol Return Value Returns a string representing the protocol scheme of the URL, including the trailing colon. Common values include: "https:" - Secure HTTP protocol "http:" - Standard HTTP protocol "file:" - Local file protocol "ftp:" - File Transfer Protocol Example ...

Read More

Check if three consecutive elements in an array is identical in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 900 Views

We are required to write a JavaScript function, say checkThree() that takes in an array and returns true if anywhere in the array there exists three consecutive elements that are identical (i.e., have the same value) otherwise it returns false. Therefore, let's write the code for this function − Example const arr = ["g", "z", "z", "v" ,"b", "b", "b"]; const checkThree = arr => { const prev = { element: null, count: 0 ...

Read More

JavaScript multiline Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 216 Views

The JavaScript multiline property is a read-only property of regular expression objects that returns true if the 'm' modifier (multiline flag) has been set, and false otherwise. The 'm' flag changes the behavior of ^ and $ anchors to match at line breaks within the string. Syntax regexp.multiline Return Value Returns a boolean value: true if the 'm' flag is set false if the 'm' flag is not set Example: Checking multiline Property ...

Read More

Formatting dynamic json array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 889 Views

Let's say, we have an array of objects like this – const arr = [ {"name1": "firstString"}, {"name2": "secondString"}, {"name3": "thirdString"}, {"name4": "fourthString"}, {"name5": "fifthString"}, {"name6": "sixthString"}, ]; We are required to write a function that takes one such array of objects and returns an object with all the properties listed in that object. So, let's write the code for this function. It can be done through the Array reduce method – Using Array.reduce() Method ...

Read More
Showing 4231–4240 of 8,010 articles
« Prev 1 422 423 424 425 426 801 Next »
Advertisements