Javascript Articles

Page 113 of 534

Detecting arrow key presses in JavaScript?

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

In JavaScript, detecting arrow key presses is essential for creating interactive web applications like games, navigation systems, and custom input controls. Arrow keys have specific key codes that JavaScript can detect through keyboard events. The four arrow keys have the following key codes: Left arrow: 37 Up arrow: 38 Right arrow: 39 Down arrow: 40 Method 1: Using keyCode with onkeydown The traditional approach uses the keyCode property to identify which arrow key was pressed: JavaScript Arrow Key Detection Click on the page and ...

Read More

How to convert a currency string to a double with jQuery or JavaScript?

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

Converting currency strings to numerical values is essential in web applications for calculations and data processing. This article demonstrates how to convert currency strings to doubles using JavaScript methods. There are two popular approaches to convert currency strings into numerical values using JavaScript built-in methods. We'll explore both methods with practical examples. Method 1: Using substring() and charCodeAt() This approach uses a loop to iterate through each character, checking if it's numeric using Unicode values: Use the charCodeAt() method to get the Unicode value of each character Use the substring() method to extract the numeric ...

Read More

I'm generating a list from an array. How can I know what element I'm clicking in JavaScript?

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

When generating lists from arrays in JavaScript, you need to identify which specific element a user clicked. This is essential for interactive applications where each list item should respond differently based on its data or position. Using Event Delegation Event delegation is the most efficient approach for handling clicks on dynamically generated elements. Instead of adding listeners to each element, you attach one listener to the parent container. const fruits = ['Apple', 'Banana', 'Orange', 'Mango']; ...

Read More

JavaScript Insert space after every two letters in string?

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

In this article we are going to learn about how to insert space after every two letters in string. Before we jump into the article let's have a quick view on the strings in JavaScript. A sequence of one or more characters—which could be numbers, or symbols—is referred to as a string. Strings are immutable primitive data types in JavaScript, which means they cannot be changed. Let's dive into the article to learn more about inserting a space after every two letters in strings. For this, we'll explore multiple approaches using replace() with regular expressions and other methods. ...

Read More

Clear element.classList in JavaScript?

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

The task we are going to perform in this article is clear element classList in JavaScript. The classList property provides methods to add, remove, toggle, and check CSS classes on HTML elements. All element objects (i.e., objects that represent elements) in a Document derive from the most general base class called Element. It contains functions and characteristics that apply to all types of elements. What is classList in JavaScript JavaScript classList is a DOM property that enables manipulation of an element's CSS classes. The read-only classList property returns a DOMTokenList containing the CSS class names of an ...

Read More

How to test if a parameter is provided to a function in JavaScript?

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

Testing if a parameter is provided to a function in JavaScript is an important part of writing effective code. It allows you to ensure that the arguments passed into your functions are valid and properly formatted for use within the function. In this article, we will discuss different methods for testing whether or not a parameter has been provided to a function in JavaScript. Let us understand the term "Parameter". A parameter is a named entity in a function definition that specifies an argument which the function can accept. It acts as a variable within the function and its ...

Read More

Pulling data from array into new independent variables JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 659 Views

In JavaScript, you can extract data from arrays and assign values to new independent variables using various techniques. This process is commonly called "destructuring" and allows you to unpack array elements into separate variables efficiently. An independent variable is a standalone variable that isn't influenced by other variables. When pulling data from arrays, these new variables become independent copies of the original array elements. Using Array Destructuring (Recommended) Array destructuring is the modern and most efficient way to extract array elements into independent variables: ...

Read More

How to add two arrays into a new array in JavaScript?

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

An ordered group of indexed elements is represented by an array, which is a type of data structure. Merging two or more arrays to create a larger array that contains all the items from the original arrays is a typical operation done on multiple arrays. In JavaScript, there are several ways to add two arrays together and create a new array. This article will go over how to properly use the concat() method and spread operator (...) to combine two separate arrays into one newly created array. Additionally, each of these methods will be discussed with examples so ...

Read More

Replacing spaces with underscores in JavaScript?

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

Let us learn about "how to replace spaces with underscores in JavaScript". This is a useful technique for formatting strings that contain multiple words, commonly used for URL slugs, file names, and database fields. We'll explore different methods to achieve this transformation and discuss their use cases and performance considerations. JavaScript provides several built-in methods to replace spaces with underscores. Here are the most commonly used approaches: replace() method with regular expressions replaceAll() method split() and join() methods Using replace() Method ...

Read More

How to compare two arrays when the key is a string - JavaScript

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

Comparing two arrays in JavaScript can be tricky when the key is a string. String comparisons are case-sensitive and require special handling to ensure proper results. Fortunately, there are several methods you can use to compare two arrays when the key is a string in JavaScript. In this article, we'll discuss how to effectively compare two arrays with strings as keys using various approaches such as map(), includes(), intersection logic, and filter(). Strings in JavaScript are used to store and modify text. A string in JavaScript is defined as zero or more characters enclosed in quotations. Data that ...

Read More
Showing 1121–1130 of 5,340 articles
« Prev 1 111 112 113 114 115 534 Next »
Advertisements