Articles on Trending Technologies

Technical articles with clear explanations and examples

How to simulate target="_blank" in JavaScript ?

Gungi Mahesh
Gungi Mahesh
Updated on 15-Mar-2026 7K+ Views

The target="_blank" attribute opens links in a new tab or window. In JavaScript, you can simulate this behavior using the window.open() method, which provides more control over how new windows are opened. The window.open() method is a built-in JavaScript function that opens URLs in new browser windows or tabs. It's supported by all modern browsers and offers flexible options for controlling the new window's behavior. Syntax window.open(URL, name, specs, replace) Parameters URL − The URL to open in the new window. If omitted, opens a blank page. ...

Read More

How to select the middle of an array? - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 685 Views

We are required to write a JavaScript function that takes in an array of numbers and returns the middlemost element(s) of the array. For arrays with odd length, there's one middle element. For arrays with even length, there are two middle elements. For example, if the array is: const arr = [1, 2, 3, 4, 5, 6, 7]; Then the output should be [4] (the middle element at index 3). Using Array Prototype Method We can extend the Array prototype to add a middle() method that returns the middle element(s): ...

Read More

I'm generating a list from an array. How can I know what element I'm clicking in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 1K+ Views

When generating lists from arrays in JavaScript, you need to identify which specific element a user clicked. This is essential for interactive applications where each list item should respond differently based on its data or position. Using Event Delegation Event delegation is the most efficient approach for handling clicks on dynamically generated elements. Instead of adding listeners to each element, you attach one listener to the parent container. const fruits = ['Apple', 'Banana', 'Orange', 'Mango']; ...

Read More

How to handle ESC keydown on JavaScript popup window?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 4K+ Views

When we press the escape key, the event generated is detected using the keyup and keydown event handlers. When the escape key is pushed on the keyboard, the event handler runs across the page. Let's dive into the article for getting better understanding on handling ESC keydown on JavaScript popup window. Using keydown Event When a key is pushed, the keydown event is triggered. The keydown event is called for all keys, regardless of whether they generate a character value, in contrast to the deprecated keypress event. While keypress shows which character was entered, keydown and keyup events ...

Read More

Sort an array and place a particular element as default value in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 411 Views

We are required to write a JavaScript function that takes in an array of literal values as the first argument and a string as the second argument. Our function should sort the array alphabetically but keeping the string provided as the second argument (if it exists in the array) as the first element, irrespective of the text it contains. Example The code for this will be − const arr = ["Apple", "Orange", "Grapes", "Pineapple", "None", "Dates"]; const sortKeepingConstants = (arr = [], text = '') => { const sorter = (a, ...

Read More

Converting ASCII to hexadecimal in JavaScript

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

Converting ASCII characters to hexadecimal is a common task in JavaScript. Each character has an ASCII code that can be represented as a hexadecimal value. Understanding ASCII to Hex Conversion Each character in a string has an ASCII code. For example, '1' has ASCII code 49, '5' has 53, and '9' has 57. Converting to hexadecimal: 49 → 31, 53 → 35, 57 → 39. Example Here's how to convert ASCII characters to their hexadecimal representation: const str = '159'; const convertToHexa = (str = '') => { const res ...

Read More

Finding longest line of 1s in a matrix in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 274 Views

Suppose, we have a binary matrix (an array of arrays that contains only 0 or 1) like this: const arr = [ [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 1] ]; We need to write a JavaScript function that takes a binary matrix as input and finds the longest line of consecutive ones. The line can be horizontal, vertical, diagonal, or anti-diagonal. For the above array, the output should be 3 because the longest line starts from arr[0][1] and spans diagonally to ...

Read More

Constructing an array of smaller elements than the corresponding elements based on input array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 204 Views

In JavaScript, constructing an array where each element represents the count of smaller numbers to the right is a common algorithmic problem. This technique is useful for data analysis, ranking systems, and competitive programming challenges. Problem Statement Given an input array of numbers, create an output array where each element represents the count of numbers smaller than the current element and located to its right in the input array. Sample Input: Input Array: [5, 2, 6, 1] Sample Output: Output Array: [2, 1, 1, 0] For element 5: two ...

Read More

How to set the text overline of Text using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 311 Views

In this tutorial, we are going to learn how to set the text overline of 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 set the text overline by using the overline property. Syntax new fabric.Text(text: String , { overline : Boolean }: Object) ...

Read More

FabricJS – How to set the border opacity of a Line while moving it?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 231 Views

In this tutorial, we are going to learn about how to set the border opacity of Line while moving using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to change the opacity of the border of a line object while moving it around ...

Read More
Showing 16201–16210 of 61,297 articles
Advertisements