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
Articles by Yaswanth Varma
Page 22 of 31
Convert set to object - JavaScript?
The task we are going to perform in this article is converting a JavaScript Set to an object. Before we jump into the methods, let's have a quick overview of Sets and objects in JavaScript. A JavaScript Set is a collection of unique values where each value can only appear once. An object in JavaScript is a data structure with properties and values, similar to a dictionary or map. Converting Sets to objects is useful when you need to work with key-value pairs instead of just values. There are several methods to convert a Set to an object ...
Read MoreJavaScript - Accept only numbers between 0 to 255 range?
In JavaScript, validating user input to accept only numbers within a specific range is a common requirement. This is particularly useful for form validation, color values (RGB components), or any scenario where you need to ensure numeric input falls within defined bounds. In this article, we will explore different methods to accept only numbers between 0 and 255 range using JavaScript. This range is commonly used for RGB color values, where each color component must be between 0 and 255. Using if else Condition The if/else statement executes a block of code when a condition is true, ...
Read MoreHow to define custom sort function in JavaScript?
Creating custom sort functions in JavaScript allows you to control exactly how array elements are ordered. By defining a custom sort function, you can sort elements in specific ways that go beyond the default string-based sorting behavior. This article will explain how to define custom sort functions in JavaScript, provide practical examples, and show different sorting techniques. Understanding the Default sort() Behavior By default, the sort() method converts elements to strings and compares them lexicographically. This can lead to unexpected results with numbers: ...
Read MoreAccessing and returning nested array value - JavaScript?
Each value in an array is referred to as an element, and each element has a certain numerical location in the array, which is referred to as its index. Nested Arrays, a feature of JavaScript, allow us to create arrays inside arrays. One or more arrays can be used as the elements of nested arrays. Although the term may be a little unclear, as we look further, it is actually rather fascinating. Understanding Nested Arrays In JavaScript, a nested array is described as an Array (outer array) inside another array (inner array). One or more inner arrays ...
Read MoreHow to open link in a new window using JavaScript?
If you want users to click on links and open those links in a new window because you want your user to stay on your site while they view the linked content, then you need to use this solution. By using JavaScript you can easily configure all of your links so that they open in a new window when clicked. Approach to Open Link in a New Window Using window.open() Method Using target="_blank" with onclick Using window.open() Method JavaScript window.open() method allows you to open a new ...
Read MoreHow to test if a URL string is absolute or relative - JavaScript?
Knowing whether a URL string is absolute or relative allows you to make decisions about content loading and routing in your JavaScript applications. In this article, we'll explore different methods to determine if a given URL string is absolute or relative. Understanding URL Types Absolute URL contains all necessary information to locate a resource, including the protocol (http/https) and domain name. Syntax https://www.tutorialspoint.com/index.htm Relative URL contains only the path information and relies on the current page's context to resolve the full location. Syntax /index.htm ../images/logo.png index.htm Method 1: ...
Read MoreHow to filter an array from all elements of another array – JavaScript?
In JavaScript, filtering an array to exclude elements present in another array is a common task. This involves removing all elements from the first array that match any element in the second array. When storing multiple values in a single variable, arrays are used. Each element of an array has a numeric index that enables access to it. Arrays in JavaScript begin at index zero and can be modified using various methods. Using filter() with includes() (Recommended) The most straightforward approach combines filter() with includes() to exclude matching elements: ...
Read MoreCapitalize a word and replace spaces with underscore - JavaScript?
In JavaScript, you can capitalize words and replace spaces with underscores using various string methods. This transformation is commonly needed for creating identifiers, constants, or formatted text. let input = "tutorials point"; console.log("Input:", input); // Expected output: "Tutorials_Point" Input: tutorials point Let's explore different methods to achieve this transformation in JavaScript. Using replace() Method The replace() method searches for a specified pattern in a string and replaces it with a new value. It accepts regular expressions for complex pattern matching. Syntax string.replace(searchValue, newValue) Example 1: Basic ...
Read MoreHow to get substring between two similar characters in JavaScript?
In JavaScript, extracting a substring between two similar characters is a common task when parsing strings. This article explores different methods to achieve this using built-in string methods. Understanding String Methods Before diving into the solution, let's understand the key methods we'll use: The substring() method extracts characters between two indices and returns a new string without modifying the original. Syntax string.substring(start, end) The split() method divides a string into an array of substrings based on a specified separator. Syntax string.split(separator, limit) Method 1: Using split() ...
Read MoreSorting an array that contains undefined in JavaScript?
In JavaScript, arrays can contain undefined values which require special handling during sorting. By default, the sort() method converts all elements to strings, placing undefined values at the end of the sorted array. Let's explore different approaches to sort arrays containing undefined values effectively. Default Behavior with sort() When using the basic sort() method on arrays with undefined, JavaScript automatically places undefined values at the end: var namearr = ["Zebra", "Yatch", undefined, "Egg", undefined]; namearr.sort(); ...
Read More