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
Front End Technology Articles
Page 320 of 652
Converting any case to camelCase in JavaScript
In this article, we create a function that can take a string in any format. Such as normal case, snake case, pascal case or any other into camelCase in JavaScript. camelCase is a writing style where each word within a phrase is capitalized, except for the first word, and there are no spaces or punctuation. Let us understand through some sample example of I/O Scenario − Sample Input - const str = 'New STRING'; Sample Output - const output = 'newString'; Converting any case to camelCase in JavaScript Converting any ...
Read MoreConverting array to phone number string in JavaScript
To convert an array to a phone number string in JavaScript can be done by formatting the array elements into the desired phone number pattern. Following are the steps to learn how to convert array to phone number string in Javascript − Ensure that the array has the correct number of elements (usually 10 for a standard phone number). Join the elements of the array into a single string. Format the string into the desired phone number pattern, such as (XXX) XXX-XXXX. Let ...
Read MoreConverting seconds in years days hours and minutes in JavaScript
In this article, we create a function that takes in a number(num) which represents the number of seconds. So, it construct and return a string that contains information of years, days, hours and minutes contained in those seconds. Converting seconds into years, days, hours, and minutes in JavaScript involves breaking down a given total of seconds into more understandable time units. This process helps display elapsed time in a readable format. For the purpose of the article, we will consider that all the years have 365 days. Let us understand through some sample example of I/O Scenario ...
Read MoreJavaScript - Check if value is a percentage?
To check the value for percentage, use a regular expression. When dealing with user input or processing data in JavaScript, it's important to make sure a value is a valid percentage. This article shows you how to check if a value is a percentage using JavaScript, highlighting a useful method that involves regular expressions. Let's say the following is our value: var value = "97%"; To check the value for percentage, we are using a regular expression that matches numbers followed by the % symbol. Using Regular Expression The best way to check ...
Read MoreJavaScript: How to filter out Non-Unique Values from an Array?
To filter out non-unique values from an array in JavaScript, you can use the filter() method, a for loop, the Set and filter() method, and the reduce() method. In this article, we will filter out non-unique values and return an array that only contains unique non-repeating elements. Arrays are data structures used to store data in a structured format. We can store the data in an array and retrieve them using their indexes. These indexes serve as a key for these values. Table of Content Filtering non-unique values from an array can be done in the following ways: ...
Read MoreJavaScript: How to map array values without using \"map\" method?
When you need to transform array elements without using the built-in map() method, JavaScript provides several alternatives. These approaches manually iterate through arrays and apply transformations to create new arrays with modified values. Table of Contents You can map array values without using the map method in the following ways: Using forEach() Using reduce() Using a for Loop Using while Loop Using forEach() The forEach() method iterates through each array element, allowing you to apply transformations while manually building a ...
Read MoreJavaScript input type=submit is not working?
The input type submit is not working is one of the common issues that developers face while working with JavaScript forms. To make it work properly, you need to handle form events correctly or prevent the default browser behavior when necessary. This article examines common reasons why a submit button might not work in JavaScript and provides practical solutions to resolve these issues. Common Reasons for Submit Button Issues The following are some common reasons that may lead to this issue: Missing Event Listener − If you haven't added an event ...
Read MoreJavaScript Sum of two objects with same properties
In JavaScript, summing two objects with identical properties is a common task when working with data aggregation. This involves creating a new object where each property's value is the sum of corresponding values from the input objects. In JavaScript, objects are data structures that store key-value pairs. When you have multiple objects with the same property names, you often need to combine their values mathematically. Understanding the Problem When you have two objects with the same property names, the goal is to create a new object where each property's value is the sum of the matching values ...
Read MoreJavaScript: Computing the average of an array after mapping each element to a value
Computing the average of an array after mapping each element to a value in JavaScript can be done using several approaches including the forEach() loop, parseInt() method, reduce() method, and for...of loop. This article demonstrates how to calculate the average by summing all array elements and dividing by the array length. Given below are examples of arrays where we compute the average by summing values and dividing by the number of elements: Input: [1, 2, 3, 4, 5] Result: 3 Explanation: (1+2+3+4+5)/5 = 3 Input: [2, 4, 7, 9, 1, 3, 8] Result: 4.857142857142857 Explanation: (2+4+7+9+1+3+8)/7 ...
Read MoreJavaScript union of two objects
In this article, we will learn to calculate the union of two objects in JavaScript. The union of two objects results in a new object that contains all the properties of both objects. What is the Union of Two Objects? The union of two objects is the process of combining the properties of both objects into a single object. When properties have the same key, their values are merged together. For example Input − const obj1 = { name: "John", email: "john@email.com" }; const obj2 = { name: "Jane", email: "jane@email.com" }; ...
Read More