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
Usage of background-color property in CSS
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 MoreHow can we validate decimal numbers in JavaScript?
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 MoreCompress array to group consecutive elements JavaScript
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 MoreHow to group JSON data in JavaScript?
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 MoreHow to use the 'with' keyword in JavaScript?
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 MoreSet the Background Image Position with CSS
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 MoreHow to access 'this' keyword inside an arrow function in JavaScript?
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 MoreWhat is "undefined x 1" in JavaScript?
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 MoreJavaScript regex program to display name to be only numbers, letters and underscore.
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 MoreES6 Property Shorthands in JavaScript
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