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 383 of 652
What is the importance of '+' operator in type conversion in JavaScript?
JavaScript is a dynamically typed language where operations often automatically convert values to the appropriate type. The + operator plays a crucial role in type conversion, behaving differently depending on the operand types. JavaScript provides many ways to convert data from one form to another, with two most common types of conversion: Converting values to strings Converting values to numbers The '+' Operator's Dual Behavior The + operator in JavaScript serves two purposes: Addition: When both operands are numbers String ...
Read MoreHow to get the Width and Height of the screen in JavaScript?
In this article, we are going to discuss how to get the width and height of the screen in JavaScript. JavaScript provides a window.screen object that contains information regarding the user's screen. The information includes height and width, and also many other features like color depth and pixel density. To find the height and width of the screen you need to use the following read-only properties: screen.height − This property returns the height of the screen in pixels. screen.width − This property returns the width of the screen in pixels. ...
Read MoreCounting below / par elements from an array - JavaScript
We are required to write a function that counts how many elements in an array are below or at/above a given number. Following is our array of Numbers − const array = [54, 54, 65, 73, 43, 78, 54, 54, 76, 3, 23, 78]; For example, if the number is 60, there should be 7 elements below it − 54, 54, 43, 54, 54, 3, 23 and 5 elements at or above it − 65, 73, 78, 76, 78 Using Array.reduce() Method The reduce() method processes ...
Read MoreHow to modify an array value of a JSON object in JavaScript?
In JavaScript, JSON objects are regular JavaScript objects that can contain arrays. Modifying array values within these objects is straightforward using array indexing or array methods. When working with JSON objects containing arrays, you can access and modify array elements just like you would with any JavaScript array, using bracket notation or array methods. Syntax To modify an array value in a JSON object: // Direct index assignment jsonObject.arrayProperty[index] = newValue; // Using array methods jsonObject.arrayProperty.push(newValue); jsonObject.arrayProperty.splice(index, 1, newValue); Method 1: Direct Index Assignment The simplest way to modify an array ...
Read MoreHow to concatenate two strings so that the second string must concatenate at the end of first string in JavaScript?
String concatenation is the process of joining two or more strings together to create a new string. In JavaScript, there are several methods to concatenate strings, with the second string being appended at the end of the first string. Using concat() Method The concat() method joins the calling string with the provided string arguments to create a new string. The original strings remain unchanged since strings in JavaScript are immutable. Syntax concat(str1) concat(str1, str2) concat(str1, str2, ... , strN) Parameters Parameter Description strN One or more strings to ...
Read MoreWhat is the importance of str.padStart() method in JavaScript?
The padStart() method in JavaScript pads a string at the beginning to reach a specified length. It's particularly useful for formatting numbers, creating aligned text, and adding prefixes with consistent string lengths. Syntax string.padStart(targetLength, padString) Parameters targetLength: The desired length of the resulting string after padding. padString (optional): The string to use for padding. Defaults to a space character if not provided. Return Value Returns a new string padded at the beginning. The original string remains unchanged. Basic Example ...
Read MoreMerging boolean array with AND operator - JavaScript
Let's say, we have an array of arrays of boolean like this − const arr = [[true, false, false], [false, false, false], [false, false, true]]; We are required to write a function that merges this array of arrays into a one-dimensional array by combining the corresponding elements of each subarray using the AND (&&) operator. Let's write the code for this function. We will be using Array.prototype.reduce() function to achieve this. Example Following is the code − const arr = [[true, false, false], [false, false, false], [false, false, true]]; const ...
Read MoreIn how many ways can we find a substring inside a string in javascript?
JavaScript provides several methods to find a substring inside a string. The most commonly used approaches are indexOf(), includes(), search(), and regular expressions with match(). Using indexOf() Method Syntax string.indexOf(substring, startPosition) The indexOf() method returns the index of the first occurrence of the substring. If the substring is not found, it returns -1. This method is case-sensitive. Example var company = "Tutorialspoint"; document.write("Index of 'point': " + company.indexOf('point')); document.write(""); document.write("Is 'Tutor' present: " + (company.indexOf('Tutor') !== ...
Read MoreHow to get the code name and product name of the browser in JavaScript?
When a user accesses a web application, the JavaScript navigator object contains details about the browser they are currently using. Since each browser functions differently in how it interprets JavaScript, the navigator object helps in adapting your application to the user's browser preferences. The browser engine or product name can be accessed in JavaScript using the navigator.product property. However, in modern browsers, navigator.product always returns "Gecko" for compatibility reasons, regardless of the actual browser being used. Navigator.product Property Syntax navigator.product Example 1: Getting Browser Product Name This example demonstrates how to access ...
Read MorePrime numbers upto n - JavaScript
Let's say, we are required to write a JavaScript function that takes in a number, say n, and returns an array containing all the prime numbers up to n. For example − If the number n is 24, then the output should be − const output = [2, 3, 5, 7, 11, 13, 17, 19, 23]; Method 1: Basic Prime Check Approach This approach uses a helper function to check if each number is prime: const num = 24; const isPrime = num => { let count ...
Read More