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
How to Create Query Parameters in JavaScript?
Query parameters are key-value pairs appended to URLs after a question mark (?). They're essential for passing data between web pages, implementing search functionality, and creating dynamic URLs. For example, when you search on Amazon, your search term becomes a query parameter in the URL. JavaScript provides several methods to create query parameters programmatically. This is useful when building search features, filtering options, or any functionality that needs to modify URLs based on user input. Using encodeURIComponent() Method The encodeURIComponent() method encodes special characters in URL components. For example, spaces become %20, and other special characters are ...
Read MoreHow to convert a plain object into ES6 Map using JavaScript?
There are many ways to convert a plain object into an ES6 Map in JavaScript. The simplest and most effective way is using the Object.entries() function and the Map() constructor. In contrast, the more flexible alternatives include Object.keys() and Array.prototype.forEach() and the for...in loop and Map() function method. A Map in ES6 is a collection of key-value pairs. Here we can use any type of object as a key, including primitive data types like strings and numbers. The values in the map can be any type of object. The main difference between a Map and an object is ...
Read MoreFinding nearest prime to a specified number in JavaScript
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. Therefore, let's write the code for this function − 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. Example The code for this will be − const num = ...
Read MoreFinding quarter based on month index in JavaScript
We are required to write a JavaScript function that takes in the 1-based month index and return the quarter which the month falls in. Understanding Quarters A year is divided into four quarters, each containing three months: Q1: January, February, March (months 1-3) Q2: April, May, June (months 4-6) Q3: July, August, September (months 7-9) Q4: October, November, December (months 10-12) Method 1: Using if-else Statements const month = 7; const findQuarter = (month = 1) => { ...
Read MoreRealtime moving average of an array of numbers in JavaScript
A moving average calculates the average of elements from the start of an array up to each position. For each element at index i, we compute the average of elements from index 0 to i. Problem We need to write a JavaScript function that takes an array of numbers and returns a new array containing the cumulative moving average at each position. Input: [1, 2, 3, 4, 5] Output: [1, 1.5, 2, 2.5, 3] The first element is the average of just the first element (1/1 = 1). The second element is the average ...
Read MoreFinding distance to next greater element in JavaScript
Problem We are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument. Our function should construct a new array for the input in which each corresponding element is the distance to the next greater element than the current element, and if there is no greater element to the right of the current element, we should push 0 for that corresponding element in the res array and finally we should return this array. Example Input and Output Input const arr = [12, 13, 14, 11, ...
Read MoreHow to set the border opacity of a Triangle while moving using FabricJS?
In this tutorial, we are going to set the border opacity of a Triangle while moving using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. We can change the opacity of a triangle while moving it around in the canvas by using the borderOpacityWhenMoving property. Syntax new fabric.Triangle({ borderOpacityWhenMoving: Number }: Object) Parameters Options (optional) − This parameter ...
Read MoreHow to Create Fullscreen API using JavaScript?
The Fullscreen API is a browser API that allows developers to request fullscreen display from the user, and to exit fullscreen when desired. Using the Fullscreen API is relatively simple. First, you must check if the browser you are using supports the Fullscreen API. You can do this by checking for the presence of the requestFullscreen method on any element. If the browser does not support the Fullscreen API, you can still provide a fullscreen experience to your users by using another method, such as opening a new browser window. The function that requests full screen display ...
Read MoreHow to add animation in Text using FabricJS?
In this tutorial, we are going to learn how to add animation in Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. Similarly, we can also animate text by using the animate method. Syntax animate(property: String | Object, value: Number | Object) Parameters ...
Read MoreHow to add content in section using jQuery/JavaScript?
Adding content to the section dynamically is useful for loading CSS, JavaScript, or meta tags after page load. jQuery and JavaScript provide several methods to accomplish this task programmatically. There are three main approaches to add content to the head section: Using jQuery's .append() method Using JavaScript's document.createElement() method Using JavaScript's insertAdjacentHTML() method Let's explore each approach with working examples. Using jQuery's .append() Method jQuery's append() method provides a simple way to add content to the head section: ...
Read More