Articles on Trending Technologies

Technical articles with clear explanations and examples

Usage of background-color property in CSS

Sravani S
Sravani S
Updated on 15-Mar-2026 148 Views

The background-color property is used to set the background color of an element. It accepts color values in various formats including color names, hexadecimal, RGB, and HSL values. Syntax background-color: color | transparent | inherit | initial; Example: Using Color Names You can use predefined color names to set the background color: Background Color Example This text ...

Read More

How can we validate decimal numbers in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 638 Views

Validating decimal numbers in JavaScript is essential for form validation and data processing. There are several reliable methods to check if a value is a valid decimal number. Method 1: Using Regular Expression Regular expressions provide precise control over decimal number validation patterns: Decimal Validation Decimal Number Validation Validate ...

Read More

Compress array to group consecutive elements JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 446 Views

We are given a string that contains some repeating words separated by dash (-) like this: const str = 'monday-sunday-tuesday-tuesday-sunday-sunday-monday-monday-monday'; console.log(str); monday-sunday-tuesday-tuesday-sunday-sunday-monday-monday-monday Our job is to write a function that returns an array of objects, where each object contains two properties: val (the word) and count (their consecutive appearance count). Expected Output Format For the above string, the compressed array should look like this: const arr = [{ val: 'monday', count: 1 }, { val: 'sunday', ...

Read More

How to group JSON data in JavaScript?

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

Grouping JSON data in JavaScript involves organizing objects by a common property. This is useful when you need to categorize data or create summary reports from complex datasets. Basic Grouping with for...in Loop The traditional approach uses a for...in loop to iterate through object keys and group items by a specific property: var details = { "1": { name: "John" }, "2": { name: "John" ...

Read More

How to use the 'with' keyword in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 6K+ Views

The with keyword in JavaScript creates a shorthand for referencing an object's properties and methods. However, it's deprecated and not recommended in modern JavaScript due to performance and security issues. Syntax with (object) { // properties used without the object name and dot } Basic Example Here's how with works with a simple object: JavaScript with Statement var person = { ...

Read More

Set the Background Image Position with CSS

mkotla
mkotla
Updated on 15-Mar-2026 626 Views

To set the background image position, use the background-position property. This CSS property controls where the background image is positioned within its container element. Syntax background-position: horizontal vertical; The property accepts various values including pixels, percentages, and keywords like left, right, center, top, and bottom. Example: Positioning with Pixels This example sets the background image position 80 pixels from the left and centers it vertically: body { ...

Read More

How to access 'this' keyword inside an arrow function in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 632 Views

The JavaScript 'this' keyword refers to the object it belongs to. Arrow functions handle 'this' differently than regular functions - they inherit 'this' from their surrounding scope rather than creating their own. How Arrow Functions Handle 'this' Arrow functions don't have their own 'this' binding. Instead, they capture the 'this' value from the enclosing lexical scope at the time they are defined. function Student(fname, grade) { this.fname = fname; this.grade = grade; this.details = function() { ...

Read More

What is "undefined x 1" in JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 236 Views

The "undefined x 1" notation is not a JavaScript feature but Chrome's way of displaying sparse arrays with uninitialized elements. Instead of showing every undefined value, Chrome uses compact notation for better readability. What Creates "undefined x n" When you create an array with the Array() constructor or have gaps in array indexes, Chrome displays uninitialized slots as "undefined x count": console.log(Array(5)); [undefined × 5] Sparse Arrays Example Arrays with missing indexes also show this notation: let arr = [1, , , 4]; // Missing elements at ...

Read More

JavaScript regex program to display name to be only numbers, letters and underscore.

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 738 Views

In this article, we will learn the regex program to validate names to contain only numbers, letters, and underscores in JavaScript. Validating user input is essential for maintaining data integrity and security in web applications. JavaScript Regex for Name Validation Regular expressions (regex) are powerful tools for defining patterns to search and validate text. A common validation requirement is ensuring a name consists only of letters (A-Z, a-z), digits (0-9), and underscore (_). To ensure that a name contains only allowed characters, we use the following regex pattern: /^\w+$/ Regex Pattern Breakdown ...

Read More

ES6 Property Shorthands in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 235 Views

ES6 introduced property shorthand syntax that simplifies object creation when the property name matches the variable name. Instead of writing name: name, you can simply write name. Syntax // ES5 way let obj = { property: property, anotherProperty: anotherProperty }; // ES6 shorthand let obj = { property, anotherProperty }; Basic Example ES6 Property Shorthands ...

Read More
Showing 18681–18690 of 61,297 articles
Advertisements