Web Development Articles

Page 307 of 801

Remove property for all objects in array in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

Removing properties from all objects in an array is a common JavaScript task. You can accomplish this using either the delete operator (which mutates the original objects) or object destructuring with the rest operator (which creates new objects). A collection of key-value pairs constitutes an object in JavaScript. A key-value pair among them is referred to as an object property. Any data type, including Number, String, Array, Object, etc., can be used for both the keys and values of properties. Method 1: Using the delete Operator (Mutable) The delete operator removes both the property's value and the ...

Read More

Calculating the area of a triangle using its three sides in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 770 Views

In JavaScript, calculating the area of a triangle using its three sides can be accomplished through mathematical formulas. This is useful when you know the side lengths but not the height or base measurements. Problem Statement Create a JavaScript function that calculates the area of a triangle given the lengths of its three sides. Sample Input: Side A: 3 units Side B: 4 units Side C: 5 units Sample Output: Area: 6 Approach We'll explore two mathematical methods to solve this problem: ...

Read More

Deleting occurrences of an element if it occurs more than n times using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 379 Views

In JavaScript, managing array elements with excessive occurrences is a common data manipulation task. This article demonstrates how to delete elements that appear more than a specified number of times while preserving the original order. Problem Statement Given an array and a positive integer n, write a JavaScript function that removes elements if they occur more than n times. The first n occurrences should be kept, and any additional occurrences should be removed. Sample Input: const arr = [1, 2, 3, 1, 2, 1, 1, 3]; const n = 2; Sample Output: ...

Read More

Finding the only unique string in an array using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 998 Views

In JavaScript, finding a unique string that appears only once in an array is a common programming challenge. This article demonstrates two effective approaches to solve this problem. Problem Statement Write a JavaScript function that takes an array of strings as input and returns the only unique string present in the array. A unique string is defined as a string that occurs only once in the given array. If there are no unique strings, the function should return null. Sample Input: const strings = ["apple", "banana", "orange", "banana", "kiwi", "kiwi", "apple"]; Sample Output: ...

Read More

Removing all spaces from a string using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several efficient methods to remove all spaces from a string. This is a common requirement in web development for tasks like data validation, formatting user input, or preparing strings for processing. Problem Statement Given a string containing spaces, we need to remove all space characters to create a continuous string without any gaps. Sample Input: "Hello world! This is a test string." Sample Output: "Helloworld!Thisisateststring." Methods to Remove Spaces We'll explore four different approaches to solve this problem: Using Regular Expression with ...

Read More

Removing punctuations from a string using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

Removing punctuation from strings is a common task in text processing applications. JavaScript provides several effective methods to accomplish this, from regular expressions to iterative approaches. Problem Statement Create a JavaScript function that removes all punctuation marks from a given string while preserving letters, numbers, and spaces. Sample Input: Hello, world! How's everything going? Sample Output: Hello world Hows everything going Using Regular Expression (Recommended) Regular expressions provide the most efficient way to remove punctuation. The pattern /[^\w\s]/g matches any character that isn't a word character (letters, digits) or whitespace. ...

Read More

Sorting numbers in ascending order and strings in alphabetical order in an array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

In JavaScript, sorting arrays that contain both numbers and strings requires a custom approach since the default sort() method converts all elements to strings. This article explores two effective methods to sort mixed arrays with numbers first (ascending) followed by strings (alphabetical). Problem Statement We need to create a JavaScript function that sorts an array containing both numbers and strings. The requirements are: Numbers should appear before strings Numbers should be sorted in ascending order Strings should be sorted alphabetically Sample Input: ["zebra", 21, "apple", 5, "orange", 13, "banana", 2] Sample ...

Read More

Checking if a string can be made palindrome in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 913 Views

In JavaScript, determining if a string can be made into a palindrome by removing at most one character is a common algorithmic problem. A palindrome reads the same forwards and backwards, like "racecar" or "level". Problem Statement Given a string, we need to check if it can become a palindrome by removing at most one character. The function should return true if possible, false otherwise. Sample Input: "racecar" Sample Output: true Using Two Pointers (Recommended) The most efficient approach uses two pointers starting from both ends of the string, moving towards the center while comparing ...

Read More

Counting matching substrings in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 261 Views

Counting matching substrings in JavaScript is essential for text analysis and string manipulation tasks. This article explores different methods to count subsequences within a string, helping developers choose the most appropriate approach for their needs. Problem Statement We need a JavaScript function that counts subsequences in a given string. The function takes a string "str" and an array of strings "arr" as input. It examines each element in "arr" and determines how many strings are subsequences of "str". A subsequence is formed by removing characters from the original string while maintaining the relative order of remaining characters. ...

Read More

In-place Algorithm to Move Zeros to End of List in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 1K+ Views

Moving zeros to the end of an array while maintaining the order of non-zero elements is a common programming problem in JavaScript. This article explores two efficient approaches to solve this problem: the in-place two-pointer method and the count-and-fill approach. Problem Statement Given an array containing integers including zeros, we need to move all zeros to the end while preserving the relative order of non-zero elements. The goal is to achieve this efficiently, ideally in a single pass through the array. For example, given the input array: [2, 5, 0, 1, 0, 8, 0, 3] ...

Read More
Showing 3061–3070 of 8,010 articles
« Prev 1 305 306 307 308 309 801 Next »
Advertisements