Front End Technology Articles

Page 299 of 652

Return correct value from recursive indexOf in JavaScript?

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

A computer pattern or idea called recursion is present in many programming languages, including JavaScript. It is a feature used to build a function that repeatedly calls itself, but with a smaller input each time, until the intended outcome of the code is realized. In this article, we will return the correct value from a recursive indexOf() function in JavaScript. Let's dive into the article for a better understanding. Understanding Recursive indexOf Implementation The position of the first occurrence of a value in a string or array is returned by the indexOf() method. -1 is returned by ...

Read More

How to handle ESC keydown on JavaScript popup window?

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

When we press the escape key, the event generated is detected using the keyup and keydown event handlers. When the escape key is pushed on the keyboard, the event handler runs across the page. Let's dive into the article for getting better understanding on handling ESC keydown on JavaScript popup window. Using keydown Event When a key is pushed, the keydown event is triggered. The keydown event is called for all keys, regardless of whether they generate a character value, in contrast to the deprecated keypress event. While keypress shows which character was entered, keydown and keyup events ...

Read More

Do JavaScript arrays have an equivalent of Python’s \"if a in list\"?

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

JavaScript provides the includes() method as the direct equivalent of Python's if item in list syntax. This method returns true if the element exists in the array, otherwise false. In Python, you check membership using: # Python syntax if "apple" in fruits: print("Found!") JavaScript achieves the same result with the includes() method, which is supported in all modern browsers and provides a clean, readable solution. Syntax array.includes(searchElement, fromIndex) Parameters searchElement − The element to search for in the array fromIndex (optional) − The position ...

Read More

How to remove all blank objects from an Object in JavaScript?

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

In JavaScript, removing blank or empty values from an object is a common task when cleaning up data. This article explores different methods to filter out empty strings, null values, or undefined properties from objects. Sample Object with Empty Values Let's work with an object containing empty values that we want to remove: const details = { name: 'John', ...

Read More

Capitalize a word and replace spaces with underscore - JavaScript?

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

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 More

How to format date value in JavaScript?

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

JavaScript provides several methods to format dates according to your requirements. The built-in Date object offers various formatting options, from simple string conversion to locale-specific formatting. Using toLocaleDateString() Method The toLocaleDateString() method formats dates according to locale and custom options, providing flexible date formatting. Example Here's how to format dates with custom options using toLocaleDateString(): var options = { year: 'numeric', ...

Read More

How do I change a tag\'s inner HTML based on their order in JavaScript?

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

In JavaScript, you can change a tag's innerHTML based on their order using document.querySelectorAll() or getElementsByClassName(). These methods return collections of elements that you can iterate through and modify based on their position in the DOM. This technique is useful for numbering elements, adding order-based content, or applying different innerHTML to similar elements based on their sequence. Using document.querySelectorAll() The querySelectorAll() method returns a static NodeList containing all elements that match the specified CSS selector(s). Syntax document.querySelectorAll(selectors) Example 1: Basic Order Assignment Here's how to change innerHTML based on element order ...

Read More

Is it possible to create a new data type in JavaScript?

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

The task we are going to perform in this article is to explore whether it's possible to create a new data type in JavaScript. For instance, let's consider we have a variable student: var student = "username"; console.log(typeof student); string Now, I want to declare a custom type for that variable and print that in the output. Let's dive into the article to learn more about creating a new data type in JavaScript. Can You Create Custom Data Types? Yes, it is possible to create custom data types in JavaScript using ...

Read More

How to count number of occurrences of repeated names in an array - JavaScript?

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

In JavaScript, counting occurrences of repeated names in an array is a common task when working with data analysis and statistics. This involves iterating through an array of objects and tracking how many times each name appears. Let's consider an array consisting of student details with repeated names: var details = [ { studentName: "John", studentAge: 23 }, { studentName: "David", studentAge: 24 ...

Read More

Make strings in array become keys in object in a new array in JavaScript?

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

The task we are going to perform in this article is to make strings in an array become keys in objects within a new array in JavaScript. Let's consider a simple array: let array = ['bike', 'car']; We want to transform this array into a new array where each string becomes a key in an object with an empty array as its value: let newArray = [{bike: []}, {car: []}]; Let's explore different methods to accomplish this transformation in JavaScript. Using map() Method The map() method creates a new array ...

Read More
Showing 2981–2990 of 6,519 articles
« Prev 1 297 298 299 300 301 652 Next »
Advertisements