Articles on Trending Technologies

Technical articles with clear explanations and examples

HTML5 Audio to Play Randomly

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 515 Views

HTML5 Audio API allows you to play audio files randomly by combining JavaScript arrays with the Math.random() method. This technique is useful for music players, games, or any application requiring random audio playback. Setting Up the Audio Collection First, initialize an array of audio sources. Each song should be added to the collection using the init() function: init ([ 'http://demo.com/songs/song1.mp3', 'http://demo.com/songs/song2.mp3', 'http://demo.com/songs/song3.mp3' ]); Complete Random Audio Player Implementation Here's a complete example that creates audio objects and implements random playback: ...

Read More

How to draw large font on HTML5 Canvas?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 316 Views

To draw large font text on HTML5 Canvas, you need to set the font size using the font property and use fillText() or strokeText() methods to render the text. Basic Syntax context.font = "size family"; context.fillText(text, x, y); context.strokeText(text, x, y); Example: Drawing Large Text Large Font Canvas var myCanvas = document.getElementById("myCanvas"); var ...

Read More

JSON. stringify( ) function in JavaScript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 323 Views

The JSON.stringify() method converts a JavaScript object or value to a JSON string. This is the reverse of JSON.parse() which converts JSON strings back to JavaScript objects. Syntax JSON.stringify(value, replacer, space) Parameters value: The JavaScript value to convert to JSON string (required) replacer: Function or array to transform values (optional) space: Number of spaces or string for indentation (optional) Basic Example JSON.stringify Example var obj = {Tutorial: "JavaScript", Version: "ES6", ...

Read More

Accessing an array returned by a function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 887 Views

In JavaScript, functions can return arrays that can be accessed and manipulated directly. This is useful for creating reusable code that generates data structures. Basic Syntax function functionName() { let array = [/* elements */]; return array; } // Access the returned array let result = functionName(); Example: Returning and Accessing Arrays Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

Strictly increasing sequence JavaScript

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

Given a sequence of integers as an array, we have to determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. For example: For sequence = [1, 3, 2, 1], the output should be function(sequence) = false. There is no one element in this array that can be removed in order to get a strictly increasing sequence. For sequence = [1, 3, 2], the output should be function(sequence) = true. You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, ...

Read More

Not able to push all elements of a stack into another stack using for loop in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 341 Views

When transferring elements from one stack to another using a for loop, you need to understand that the stack follows the Last In First Out (LIFO) principle. The key is to pop() elements from the source stack and push() them into the destination stack. The Stack Transfer Process When you pop elements from the first stack and push them into the second stack, the order gets reversed because of the LIFO nature: var myFirstStack = [10, 20, 30, 40, 50, 60, 70]; var mySecondStack = []; console.log("Original first stack:", myFirstStack); console.log("Original second stack:", mySecondStack); ...

Read More

Nearest Prime to a number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 601 Views

We are required to write a JavaScript function that takes in a number and returns the first prime number that appears after n. For example: If the number is 24, then the output should be 29. Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Examples include 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, etc. Implementation We'll create two functions: one to check if a number is prime, and another to find the nearest prime after a given ...

Read More

How to skip character in capture group in JavaScript Regexp?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 1K+ Views

You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions. However, you can use techniques to extract specific parts while ignoring unwanted characters. Understanding the Problem When you need to match a pattern but only capture certain parts, you can use non-capturing groups (?:...) and capturing groups (...) strategically to ignore unwanted characters. Example: Extracting Username After Prefix The following example shows how to match a string with a prefix but only capture the username part: ...

Read More

What is the usage of onpageshow event in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 253 Views

The onpageshow event triggers in JavaScript when a user navigates to a web page, including when the page loads for the first time or when returning from the browser's back/forward cache (bfcache). Syntax // HTML attribute // Event listener window.addEventListener('pageshow', function(event) { // Handle page show }); Example: Basic Usage Here's how to implement the onpageshow event using HTML attribute: On first visit, a welcome message is visible. ...

Read More

Rotate HTML5 Canvas around the current origin

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 577 Views

HTML5 canvas provides the rotate(angle) method which rotates the canvas around the current origin point. This method is essential for creating rotated graphics and animations. Syntax context.rotate(angle); Parameters The method takes one parameter: angle: The rotation angle in radians (clockwise direction) To convert degrees to radians, use: radians = degrees * (Math.PI / 180) Basic Rotation Example Here's a simple example showing how to rotate a rectangle: canvas { ...

Read More
Showing 17831–17840 of 61,297 articles
Advertisements