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
Web Development Articles
Page 413 of 801
How to Clear the JavaScript Console in Google Chrome
In this article, we'll learn how to clear the JavaScript console in Google Chrome. When developing web applications, the console often gets cluttered with logs, errors, and debug messages, making it difficult to read new output. There are multiple ways to clear the Chrome console, each useful in different scenarios. Let's explore the most common methods. Using the console.clear() Method The console.clear() method programmatically clears the console and displays a "Console was cleared" message. Example Click the button to clear the console. Clear Console ...
Read MoreSort Array of numeric & alphabetical elements (Natural Sort) JavaScript
We have an array that contains some numbers and some strings. We are required to sort the array such that the numbers get sorted and placed before every string, and then the strings should be placed sorted alphabetically. For example, this array: const arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9]; console.log("Original array:", arr); Original array: [ 1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9 ] Should look like this after sorting: [1, 6, 7, 9, 47, 'afv', 'bdf', 'fdf', 'svd'] Implementation ...
Read MoreInserting string at position x of another string using Javascript
In this article, you are going to learn how to insert a string at a position in another string. JavaScript does not provide a direct method to insert a string at a specific position. However, we can achieve this using various string methods like slice(), substr(), and array methods like join(). Using the slice() Method The slice() method extracts a section of a string and returns a new string without modifying the original string. Syntax String.slice(start, end) Parameters start − Required. The position from where to start ...
Read MoreConverting a string to a date in JavaScript
In this article, we are going to discuss how to convert a string value to a Date object in JavaScript. There are two ways to achieve this − Using the constructor of the Date class − This constructor accepts a string value representing the date value, converts it into a Date object, and returns the result. Using the Date.parse() method − Same as the Date constructor this method accepts a string value parses and returns the date value in the form of milliseconds. Let us see these solutions with examples − Using the Date() constructor ...
Read MoreHow to clone a js object except for one key in javascript?
In JavaScript, cloning an object except for one key means creating a copy of an object while excluding specific properties. This is a common requirement when you need to create modified versions of objects without mutating the original. There are several approaches to accomplish this, depending on whether you need a shallow or deep clone: Shallow Clone - Copies only the top-level properties Deep Clone - Recursively copies all nested objects and arrays Understanding Shallow vs Deep Cloning Shallow Clone A shallow clone copies the object's structure but not nested objects. Both the original ...
Read MoreObject literals vs constructors in JavaScript
Object literals and constructors are two fundamental ways to create objects in JavaScript. Object literals create singleton objects, while constructor functions can create multiple instances with shared behavior. Object Literal Notation Object literals use curly braces {} to define properties and methods directly. They are ideal for creating single-use objects or configuration objects. Object Literal Example const userDetails = { name: "Aman", ...
Read MoreJavaScript symbol.description property
The symbol.description property in JavaScript returns the description string of a Symbol. Unlike Symbol.toPrimitive, the description property provides access to the optional description passed when creating a Symbol. Syntax symbol.description Return Value Returns the description string of the Symbol, or undefined if no description was provided during Symbol creation. Example: Symbol with Description Symbol Description Example Click to display symbol description... Show Description function display() { const sym1 = Symbol('user-id'); const ...
Read MoreConverting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?
We need to write a function that reads a string and converts the odd indexed characters in the string to upperCase and the even ones to lowerCase and returns a new string. Understanding Index-Based Case Conversion In JavaScript, string indices start at 0. Even indices (0, 2, 4...) will be converted to lowercase, while odd indices (1, 3, 5...) will be converted to uppercase. Example const text = 'Hello world, it is so nice to be alive.'; const changeCase = (str) => { const newStr = str ...
Read MoreRecursive sum all the digits of a number JavaScript
Let's say, we are required to create a function that takes in a number and finds the sum of its digits recursively until the sum is a one-digit number. For example − findSum(12345) = 1+2+3+4+5 = 15 = 1+5 = 6 So, the output should be 6. How Recursive Digit Sum Works The process involves two levels of recursion: Extract and sum individual digits of a number Repeat the process until we get a single digit Method 1: Using Mathematical Operations ...
Read MoreHow to make a list of partial sums using forEach JavaScript
In JavaScript, creating a list of partial sums (also known as cumulative sums) means generating a new array where each element represents the sum of all elements up to that position in the original array. We have an array of numbers like this: const arr = [1, 1, 5, 2, -4, 6, 10]; We need to create a function that returns a new array where each element is the sum of all previous elements including itself: const output = [1, 2, 7, 9, 5, 11, 21]; Using forEach Method The ...
Read More