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 208 of 801
JavaScript - Sort key value pair object based on value?
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 MoreSet PIN validation with JavaScript?
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 MoreDynamically replace data based on matched RegEx - JavaScript?
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 MoreApplying a custom function to each corresponding element of two arrays using JavaScript
We need to write a JavaScript function that applies a custom callback function to corresponding elements of two arrays, creating a new array with the results. Problem We are required to write a JavaScript function that takes in a callback function (which takes in two arguments and returns a value) as the first argument and two arrays of essentially the same length as the second and third argument. Our function should construct and return a new array whose each corresponding element is the return value of the callback function if corresponding numbers of the input array are ...
Read MoreInsert a new CSS rule while working on JavaScript?
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 MoreMultiply only specific value in a JavaScript object?
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 MoreDelete all text up to a character in a URL- JavaScript?
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 MoreFinding alphabet from ASCII value without using library functions in JavaScript
Problem We are required to write a JavaScript function that takes in a number representing an ASCII value. Our function should return the corresponding alphabet character for that ASCII value (if it exists), or -1 otherwise. The condition here is that we cannot use any built-in function like String.fromCharCode() that directly converts ASCII values to characters. Understanding ASCII Values ASCII values for alphabetic characters follow these ranges: Uppercase letters: A-Z have ASCII values 65-90 Lowercase letters: a-z have ASCII values 97-122 Example Following is the code: const num = ...
Read MoreValidate Tutorialspoint URL via JavaScript regex?
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 MoreFinding the length of longest vowel substring in a string using JavaScript
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