Articles on Trending Technologies

Technical articles with clear explanations and examples

Remove number properties from an object JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 325 Views

In JavaScript, we often need to filter object properties based on their data types. This article demonstrates how to remove properties of a specific type from an object using a reusable function. Problem Statement Given an object with mixed property types (numbers, strings, booleans, objects), we need to create a function that removes all properties of a specified data type. If no type is specified, it should default to removing number properties. Solution We'll create a function called shedData that iterates through object properties and deletes those matching the specified type: const obj = ...

Read More

Converting string to MORSE code in JavaScript

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

What is Morse Code? Morse code is a method used in telecommunications to encode text characters as standardized sequences of two different signal durations, called dots and dashes. Each letter of the alphabet has a unique pattern of dots (.) and dashes (-). To convert a string to Morse code in JavaScript, we need an object that maps all alphabets to their Morse code equivalents, then iterate through the input string to build the encoded result. Morse Code Map First, let's create an object containing all alphabet-to-Morse mappings: const morseCode = { ...

Read More

How to match strings that aren't entirely digits in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 120 Views

In JavaScript, you can use regular expressions to match strings that contain non-digit characters. This is useful when parsing complex data strings where you need to identify values that aren't purely numeric. Problem Statement Consider this complex string containing various data types: studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678" We want to extract values that contain characters other than digits, excluding boolean values and null. Using Regular Expression The following regular expression matches strings that aren't entirely digits: var regularExpression = /(?

Read More

Why in JavaScript, "if ('0' == false)" is equal to false whereas it gives true in "if(0)" statement?

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

JavaScript's comparison behavior can be confusing when mixing different data types. Let's examine why '0' == false returns true while if(0) evaluates to false. Understanding '0' == false When using the loose equality operator ==, JavaScript performs type coercion following specific rules: console.log('0' == false); // true console.log(typeof '0'); // "string" console.log(typeof false); // "boolean" true string boolean The comparison follows this rule: If Type(y) is Boolean, return the result of the comparison x == ToNumber(y) Here's what happens step by step: ...

Read More

How to write JavaScript Regular Expression for multiple matches?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 285 Views

To find multiple matches in JavaScript, use the global flag (g) with regular expressions. The exec() method can be called repeatedly to find all matches in a string. Syntax let regex = /pattern/g; let matches; while ((matches = regex.exec(string)) !== null) { // Process each match } Example: Extracting URL Parameters This example extracts all demo parameters from a URL query string: var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three'; var a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g; var matches; var demo = []; ...

Read More

How to return a number of bits used to display one color on a window screen in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 309 Views

In this tutorial, we will explore how we can find out the number of bits that are used to display a single color on the screen of our device using JavaScript. JavaScript has many inbuilt functions that allow us to get information about the various properties of the display screen. We'll be using one such function to accomplish the task mentioned above. As discussed in the previous section, we want to find out the exact number of bits that are used to display a particular color on the user's display screen by using JavaScript. Before we can access the ...

Read More

How to set the minimum number of lines for an element that must be visible at the top of a page in JavaScript?

George John
George John
Updated on 15-Mar-2026 194 Views

The orphans CSS property sets the minimum number of lines in a block container that must be shown at the top of a page when a page break occurs. In JavaScript, you can control this property through the DOM to manage print layout behavior. Syntax // Get the orphans value var orphansValue = element.style.orphans; // Set the orphans value element.style.orphans = "number|initial|inherit"; Parameters Value Description number Minimum number of lines (default is 2) initial Sets to default value inherit Inherits from parent element ...

Read More

Do any browsers yet support HTML5's checkValidity() method?

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

Yes, modern browsers widely support HTML5's checkValidity() method. This method validates form elements against their HTML5 constraints and returns true if valid, false otherwise. Browser Support The checkValidity() method is supported in all modern browsers including Chrome, Firefox, Safari, Edge, and Opera. It's been widely supported since around 2012-2013. Syntax element.checkValidity() Return Value Returns true if the element meets all validation constraints, false otherwise. Example .valid { ...

Read More

Blending two images with HTML5 canvas

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 2K+ Views

To blend two images using HTML5 canvas, you need to manipulate pixel data from both images and combine them in equal proportions (50-50). This technique uses the canvas getImageData() and putImageData() methods. HTML Structure First, set up the HTML elements with the images and canvas: Blended image: window.onload = function () { var myImg1 = document.getElementById('myImg1'); var myImg2 = document.getElementById('myImg2'); var myCanvas = document.getElementById("canvas"); var ctx = myCanvas.getContext("2d"); // ...

Read More

How to implement quick sort in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to discuss how to implement quick sort in JavaScript with suitable examples. Quick Sort The Quick sort is a divide and conquer algorithm similar to the merge sort. In this, we pick a pivot element and divide the array around the pivot element. There are many ways to pick the pivot element. Always pick the first element as a pivot element. Always pick the last element as a pivot element. (Implemented in the below program) Pick a random element as pivot ...

Read More
Showing 17761–17770 of 61,297 articles
Advertisements