Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Highest occurrence in an array or first selected in JavaScript
We are required to write a JavaScript function that takes in an array of literal values. Our function should then return the highest occurrence of an array value, and if there's an equal occurrence, we should return the first selected value of the equal occurrences. Problem Statement Given an array of values, find the element that appears most frequently. If multiple elements have the same highest frequency, return the one that appears first in the array. const arr1 = ['25', '50', 'a', 'a', 'b', 'c']; // 'a' appears 2 times (most frequent), so return 'a' ...
Read MoreTraversing Diagonally in a matrix in JavaScript
In JavaScript, traversing a matrix diagonally means moving through the elements in a zigzag pattern from top-left to bottom-right. This technique is useful for various algorithms including matrix processing and image manipulation. Problem Statement We need to write a JavaScript function that takes a square matrix (array of arrays with equal rows and columns) and traverses it diagonally, creating a new array with elements in the order they were encountered. For example, given this input matrix: const arr = [ [1, 2, 3], [4, 5, 6], ...
Read MoreHow to round up a number in JavaScript?
In JavaScript, the Math.ceil() method rounds a number up to the nearest integer. Unlike regular rounding, it always rounds upward, making it useful for scenarios like calculating pages needed or ensuring minimum values. Syntax Math.ceil(x) Where x is the number to round up. The method returns the smallest integer greater than or equal to x. How Math.ceil() Works If the number is already an integer, it returns the same number If the number has any decimal part (even 0.1), it rounds up to the next integer ...
Read MoreHow to load the next URL in the history list in JavaScript?
In this tutorial, we will learn to load the next page in the history list in JavaScript. The Window object in JavaScript accesses the window in the browser. This object contains many properties and methods required to do the tasks. The Window object also retrieves the information from the browser window. There is a history stack in every browser that saves the pages visited by the user. To access this history stack, we can use the history object that is the property of the Window object. By accessing the history from the browser, we can go to the ...
Read MoreHow to set how the last line of a block or a line right before a forced line break is aligned when text-align is "justify" with JavaScript?
The textAlignLast property in JavaScript controls how the last line of a text block is aligned when the text uses text-align: justify. This is particularly useful for controlling the alignment of the final line in justified paragraphs. Syntax element.style.textAlignLast = "value"; Common Values The textAlignLast property accepts these values: auto - Default behavior (usually left-aligned) left - Aligns last line to the left right - Aligns last line to the right center - Centers the last line justify - Justifies the last line (stretches it) Example: Setting Last Line Alignment ...
Read MoreCan Google Analytics track interactions in an offline HTML5 app?
Google Analytics is a freemium analytic tool that provides detailed statistics of web traffic. It is used by more than 60% of website owners. Analytics tools offer insights into website performance, visitor behavior, and data flow. These tools are inexpensive and easy to use, sometimes even free. Yes, Google Analytics can track interactions in offline HTML5 apps, but with specific limitations and considerations. How Offline Tracking Works When an HTML5 application goes offline, Google Analytics stores tracking events in the browser's local storage or SQLite database. After storing these events, it waits until the user comes back ...
Read MoreConvert text to lowercase with CSS
To convert text to lowercase with CSS, we will be using the lowercase value of text-transform property. Syntax selector { text-transform: lowercase; } Example In this example, we are using text-transform property and displaying the result as before and after the conversion using p tag. #lcase { text-transform: lowercase; } ...
Read MoreClear the float of an element with Bootstrap
To clear the float of an element in Bootstrap, use the .clearfix class. This utility class ensures that a container properly wraps around its floated child elements, preventing layout issues. What is Float Clearing? When elements are floated (using float: left or float: right), their parent container may collapse because floated elements are taken out of the normal document flow. The .clearfix class solves this by forcing the parent to contain its floated children. Example Here's how to use Bootstrap's .clearfix class to clear floated elements: ...
Read MoreHow to Title Case a sentence in JavaScript?
Title case formatting converts the first letter of each word in a sentence to uppercase while keeping the remaining letters lowercase. This is commonly used for headings, titles, and proper formatting of text. Algorithm Split the sentence into individual words using string.split() method Convert all letters in each word to lowercase using string.toLowerCase() method Loop through each word and capitalize the first letter using toUpperCase() Concatenate the capitalized first letter with the remaining lowercase letters Join all words ...
Read MoreHow to parse an URL in JavaScript?
JavaScript provides several methods to parse URLs and extract their components like protocol, hostname, pathname, and query parameters. The modern approach uses the built-in URL constructor, while legacy methods involve creating DOM anchor elements. Using the URL Constructor (Modern Approach) The URL constructor is the standard way to parse URLs in modern JavaScript. It creates a URL object with all components easily accessible. const url = new URL("https://www.youtube.com/watch?v=tNJJSrfKYwQ"); console.log("Protocol:", url.protocol); console.log("Host:", url.host); ...
Read More