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
Javascript Articles
Page 323 of 534
How to exclude certain values from randomly generated array JavaScript
We need to create a function that generates an array of random numbers while excluding certain values. The function takes two arguments: the desired array length and an array of numbers to exclude. Requirements: Generate random numbers between 0 and 100 Exclude numbers present in the exclusion array No duplicate numbers in the result Example const absentArray = [44, 65, 5, 34, 87, 42, 8, 76, 21, 33]; const len = 10; const generateRandom = (len, absentArray) => { const randomArray = []; for(let i ...
Read MoreHow to set the style of the right border with JavaScript?
In this tutorial, we will learn to set a style of the right border with JavaScript. To set the style of the right border in JavaScript, use the borderRightStyle property. Set the style of the right border using this property. We can apply borders to an element from any side or all sides. We can customize that border on any side. Every edge of a border has a specific property that can use only for that edge. We can provide three parameters like style, color, and width for creating a border. CSS is used to do such tasks. But, ...
Read MoreHow to set the width of the right border with JavaScript?
This tutorial will teach us to set the width of the right border with JavaScript. To set the width of the right border, use the borderRightWidth property. Set the width of the right border using this property. We can also apply the borderWidth to set the right border. Borders are used on various elements on a webpage. They display the boundaries of an element. We can apply the borders to all sides of an element. There are different properties to set different sides of a border. For a static border, generally, CSS is used. But to change it dynamically, ...
Read MoreHow to find the coordinates of the cursor with JavaScript?
In this tutorial, we will learn how to find the coordinates of the mouse cursor with JavaScript. We need to determine the X and Y coordinates (horizontal and vertical positions) of the cursor on the screen when mouse events occur. JavaScript provides us with two essential properties to get the coordinates of the mouse cursor when events are triggered: Using event.clientX Property Using event.clientY Property Using event.clientX Property The event.clientX property returns the horizontal position (X-coordinate) of the cursor relative to the browser's viewport when an event is ...
Read MoreWhich is the event when the browser window is resized in JavaScript?
The resize event fires when the browser window is resized. You can listen for this event using window.addEventListener() or the onresize attribute to detect window size changes. The resize Event The resize event is triggered whenever the browser window dimensions change. This includes maximizing, minimizing, or manually dragging the window borders. Method 1: Using addEventListener() Window Resize Event Window Resize Detector Resize your browser window to see the dimensions update: ...
Read MoreHow to create a random number between a range JavaScript
Our job is to create a function, say createRandom, that takes in two arguments and returns a pseudorandom number between the range (max exclusive). Syntax const createRandom = (min, max) => { const diff = max - min; const random = Math.random(); return Math.floor((random * diff) + min); } Example const min = 3; const max = 9; const createRandom = (min, max) => { const diff = max - min; const random ...
Read MoreHow to search the value of the type attribute of a link in JavaScript?
To search or retrieve the value of the type attribute of a link in JavaScript, you can use the type property of the anchor element. This attribute specifies the MIME type of the linked resource. Syntax element.type Example: Getting Type Attribute Value Qries var x = document.getElementById("qriesid").type; document.write("Value of the type attribute: " + x); ...
Read MoreSort Array of numeric & alphabetical elements (Natural Sort) JavaScript
We have an array that contains some numbers and some strings. We are required to sort the array such that the numbers get sorted and placed before every string, and then the strings should be placed sorted alphabetically. For example, this array: const arr = [1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9]; console.log("Original array:", arr); Original array: [ 1, 'fdf', 'afv', 6, 47, 7, 'svd', 'bdf', 9 ] Should look like this after sorting: [1, 6, 7, 9, 47, 'afv', 'bdf', 'fdf', 'svd'] Implementation ...
Read MoreHow Is Infinity converted to Boolean in JavaScript?
In JavaScript, Infinity and -Infinity are special numeric values representing positive and negative infinity. When converting these values to Boolean, they always evaluate to true because they are considered "truthy" values. This tutorial demonstrates three methods to convert Infinity values to Boolean in JavaScript: Using the Boolean() Method Using the Logical NOT(!) Operator Converting Infinity to String to Boolean Using the Boolean() Method The Boolean() constructor converts any value to its boolean equivalent. For Infinity and -Infinity, this method returns true since both are truthy ...
Read MoreConverting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?
We need to write a function that reads a string and converts the odd indexed characters in the string to upperCase and the even ones to lowerCase and returns a new string. Understanding Index-Based Case Conversion In JavaScript, string indices start at 0. Even indices (0, 2, 4...) will be converted to lowercase, while odd indices (1, 3, 5...) will be converted to uppercase. Example const text = 'Hello world, it is so nice to be alive.'; const changeCase = (str) => { const newStr = str ...
Read More