Front End Technology Articles

Page 207 of 652

JavaScript - Sort key value pair object based on value?

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

By using JavaScript's native array methods and functions, we can easily create custom sorting algorithms that will work for any type of object. In this article, we will discuss how to use these techniques in order to sort an object's key-value pairs by value. A key-value pair in JavaScript such as maps, dictionaries stores one value (the "key") associated with another value (the "value"). It can be used to store and access data quickly, as each element has its own unique identifier. For sorting key value pair object based on the value, we use sort() method in JavaScript. ...

Read More

Set PIN validation with JavaScript?

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

In this article, we will discuss how to set up PIN validation using JavaScript. We will cover creating prompts for users to enter their PIN number, validating input against stored values, and returning appropriate responses based on the validation result. Data validation is the procedure used to ensure that user input is accurate, reliable, and clean. PIN validation typically checks the length, format, and data type to ensure the PIN contains only digits and meets specific requirements. We can validate PINs based on length (usually 4 or 6 digits) and ensure the input contains only numeric characters. Let's ...

Read More

Dynamically replace data based on matched RegEx - JavaScript?

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

Regex (Regular Expressions) is used to match patterns in strings of text. With JavaScript, you can use regex to dynamically replace data based on matched patterns using the replace() method. This article will explain how to use regex and JavaScript together to make dynamic replacements in your code. We'll cover the basics of regex syntax and practical examples for template replacement. Using replace() Method The replace() method in JavaScript searches a string for a specified value or regular expression and returns a new string with replacements. The original string remains unchanged. Syntax string.replace(searchValue, newValue) ...

Read More

Finding the length of longest vowel substring in a string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 586 Views

Problem We are required to write a JavaScript function that takes in a string. Our function should return the length of the longest contiguous substring that contains only vowels. Approach The solution uses a sliding window approach to track consecutive vowels. We maintain two variables: cur for the current vowel sequence length and max for the longest sequence found so far. Example Following is the code − const str = 'schooeal'; const findLongestVowel = (str = '') => { let cur = 0; let max ...

Read More

Insert a new CSS rule while working on JavaScript?

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

Adding a new CSS rule can help to create the desired look and feel for your web page or application. This article will explain how to insert a new CSS rule while working on JavaScript. It will provide step-by-step instructions on how to write and apply the necessary code in order to achieve the desired result. Additionally, we will also discuss some of the potential problems that may arise when inserting a new CSS rule into an existing project. The style sheet language known as CSS (cascading style sheets), is used to shape the HTML elements that will ...

Read More

Multiply only specific value in a JavaScript object?

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

The ability to multiply only specific values in a JavaScript object can be a useful tool for performing calculations or making modifications to data. By using methods like map(), forEach(), and traditional loops, you can efficiently target and modify values that meet certain criteria. An object in JavaScript is a separate entity having properties and a type. This article demonstrates various approaches to selectively multiply values within objects and arrays. Method 1: Using Array.map() to Transform Object Properties In this example, we multiply the value property of each object in an array by 3: ...

Read More

Delete all text up to a character in a URL- JavaScript?

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

This article explains how to use JavaScript's replace() method with regular expressions to delete all text up to a specific character in a URL. This technique is useful for extracting filenames, removing domain information, or cleaning URL strings. A regular expression (RegExp) is a pattern used to match character combinations in strings. In JavaScript, regular expressions are objects with properties and methods for pattern matching and text manipulation. The replace() Method The replace() method searches for a value or regular expression pattern in a string and returns a new string with the matched content replaced. The original ...

Read More

Finding and returning uncommon characters between two strings in JavaScript

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

Problem We are required to write a JavaScript function that takes in two strings. Our function should return a new string of characters which is not common to both the strings. Example Following is the code − const str1 = "xyab"; const str2 = "xzca"; const findUncommon = (str1 = '', str2 = '') => { const res = []; for (let i = 0; i < str1.length; i++){ if (!(str2.includes(str1[i]))){ ...

Read More

Validate Tutorialspoint URL via JavaScript regex?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 260 Views

To validate a TutorialsPoint URL using JavaScript, you can use regular expressions to check if the URL matches the expected domain pattern and extract specific parts of the URL. Regular Expression Pattern The regex pattern /^https?:\/\/(tutorialspoint\.com)\/(.*)$/ breaks down as follows: ^ - Start of string https? - Matches "http" or "https" :\/\/ - Matches "://" (tutorialspoint\.com) - Captures the domain (escaped dot) \/ - Matches forward slash (.*)$ - Captures everything after the domain until end of string Example function validateTutorialspointURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; ...

Read More

Returning the value of nth power of iota(i) using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 185 Views

In mathematics, the imaginary unit i is defined as the square root of -1. When calculating powers of i, the results follow a cyclic pattern that repeats every 4 powers. Mathematical Background The imaginary unit i has the following properties: i = √(-1) i² = -1 i³ = -i i⁴ = 1 Since i⁴ = 1, the pattern repeats every 4 powers. This means we can use the modulo operator to determine the result for any power of i. Power Pattern Power (n % 4) Result (iⁿ) 0 ...

Read More
Showing 2061–2070 of 6,519 articles
« Prev 1 205 206 207 208 209 652 Next »
Advertisements