Web Development Articles

Page 413 of 801

How to Clear the JavaScript Console in Google Chrome

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 16K+ Views

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 More

Sort Array of numeric & alphabetical elements (Natural Sort) JavaScript

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

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 More

Inserting string at position x of another string using Javascript

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 1K+ Views

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 More

Converting a string to a date in JavaScript

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 4K+ Views

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 More

How to clone a js object except for one key in javascript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 2K+ Views

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 More

Object literals vs constructors in JavaScript

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 1K+ Views

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 More

JavaScript symbol.description property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 157 Views

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 More

Converting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?

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

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 More

Recursive sum all the digits of a number JavaScript

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

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 More

How to make a list of partial sums using forEach JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 347 Views

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
Showing 4121–4130 of 8,010 articles
« Prev 1 411 412 413 414 415 801 Next »
Advertisements