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
With JavaScript RegExp search a carriage return character.
To find carriage return characters with JavaScript Regular Expression, use the \r metacharacter. This pattern matches the carriage return character (ASCII code 13) in strings. Syntax /\r/ Example: Finding Carriage Return Position The following example shows how to search for a carriage return character and return its position in the string: JavaScript Regular Expression ...
Read MoreHow to set the right position of a positioned element with JavaScript?
In this tutorial, we shall learn to set the right position of a positioned element with JavaScript. What is a positioned element? The available position values in CSS are relative, absolute, fixed, or static. The static position is the default position value. Static elements are in the document order. A positioned element's position is based on its properties like the top, right, bottom, and left. We must set the position in every direction to align the elements as required. Here we are going to see the right position property. Using the right Property With this ...
Read MoreWhat are the advantages of CSS?
CSS or Cascading Style Sheets is used to design web pages, helping web developers control the layout and other visual aspects of websites. Using CSS, you can control the color of text, the style of fonts, spacing between paragraphs, how columns are sized and laid out, and what background images or colors are used. In this article, we will discuss the various advantages of CSS and why it's essential for modern web development. Key Advantages of CSS 1. Consistent Design Across Multiple Pages CSS enables uniform design across an entire website. By creating an external stylesheet and linking ...
Read MoreHow to access a function property as a method in JavaScript?
In JavaScript, object properties can hold functions, which become methods when accessed through the object. A method is simply a function that belongs to an object and can access the object's other properties using the this keyword. Syntax const object = { property1: value1, property2: value2, methodName: function() { return this.property1 + this.property2; } }; // Call the method object.methodName(); Example 1: Employee Object with fullName Method Here's an ...
Read MoreSort array by year and month JavaScript
Sorting arrays of objects by multiple criteria is a common requirement in JavaScript applications. In this tutorial, we'll learn how to sort an array by year first, then by month for objects with the same year. The Problem We have an array of objects containing year and month properties: const arr = [{ year: 2020, month: 'January' }, { year: 2017, month: 'March' }, { year: 2010, month: 'January' }, { ...
Read MoreReturn the difference between the maximum & minimum number formed out of the number n in JavaScript
We have to write a function that takes a positive number n and returns the difference between the maximum number and the minimum number that can be formed from its digits. For example, if the number n is 203: The maximum number that can be formed from its digits will be 320 The minimum number that can be formed from its digits will be 23 (placing the zero at one's place) And the difference will be: 320 - 23 = 297 Therefore, the output should ...
Read MoreAttach event to dynamic elements in JavaScript?
To attach events to dynamic elements in JavaScript, use event delegation with document.addEventListener(). This technique listens on a parent element (like document) and handles events from child elements that may be created dynamically. Why Event Delegation? When elements are added to the DOM dynamically (after the page loads), direct event listeners won't work because they weren't attached when the element was created. Event delegation solves this by using event bubbling. Basic Event Delegation Example Dynamic Events Example ...
Read MoreObject to array - JavaScript
Converting an object to an array of key-value pairs is a common task in JavaScript. There are several built-in methods to achieve this transformation. Sample Object Let's start with this example object: const obj = { name: "Vikas", age: 45, occupation: "Frontend Developer", address: "Tilak Nagar, New Delhi", experience: 23, salary: "98000" }; Using Object.entries() (Recommended) The simplest approach is using Object.entries(), which directly converts an object to an ...
Read MoreRemoving redundant elements from array altogether - JavaScript
We are required to write a function that takes in an array and returns a new array that have all duplicate values removed from it. The values that appeared more than once in the original array should not even appear for once in the new array. For example, if the input is: const arr = [763, 55, 43, 22, 32, 43, 763, 43]; The output should be: const output = [55, 22, 32]; Understanding the Approach We will be using the following two methods: ...
Read MoreHow to get a number value of a string in Javascript?
To extract numeric values from strings in JavaScript, you have several approaches depending on your needs. The most common methods are using regular expressions with parseInt(), parseFloat(), or Number(). Using parseInt() with Regular Expression For extracting integers from strings containing mixed content, combine parseInt() with match() and a regex pattern: var myStr = "abcdef 30"; var num = parseInt(myStr.match(/\d+/)); console.log("Extracted number:", num); ...
Read More