Javascript Articles

Page 320 of 534

How do I search through an array using a string, which is split into an array with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 275 Views

We are given an array of strings and another string for which we are required to search in the array. We can filter the array checking whether it contains all the characters that user provided through the input. Using Array Filter with Split (Flexible Search) This approach splits the search string into parts and checks if each part exists in the array elements, regardless of order. const deliveries = ["14/02/2020, 11:47, G12, Kalkaji", "13/02/2020, 11:48, A59, Amar Colony"]; const input = "g12, kal"; const pn = input.split(" "); const requiredDeliveries = deliveries.filter(delivery => ...

Read More

How to set the amount by which the border image area extends beyond the border box with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 228 Views

In this tutorial, we will learn how to set the amount by which the border image area extends beyond the border box in JavaScript. To set the amount by which the border image is extended, you need to set the border outside edges. To do this we can apply the borderImageOutset style property provided in JavaScript. After creating a border image area for the HTML element, we might have to increase the area. By knowing a method to increase the border image area more than the border box, we can make the change without writing lengthy code. Using ...

Read More

What is the usage of onreset event in JavaScript?

Anjana
Anjana
Updated on 15-Mar-2026 447 Views

The onreset event is triggered when a form is reset using a reset button or the reset() method. This event allows you to execute JavaScript code when users clear form data. Syntax // form elements // Or using addEventListener form.addEventListener('reset', functionName); Example: Basic onreset Event onreset Event Example function resetFunct() { alert("The form was ...

Read More

Is there any way I can call the validate() function outside the initValidation() function in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 216 Views

When you define a function inside another function in JavaScript, it's only accessible within the parent function's scope. To call the validate() function outside of initValidation(), you have several approaches. The Problem In the following code, validate() is scoped inside initValidation() and cannot be accessed externally: function initValidation(){ // irrelevant code here function validate(_block){ // code here } } Method 1: Using Constructor Pattern Convert the parent function into a constructor and assign ...

Read More

What is the usage of onsearch event in JavaScript?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 419 Views

The onsearch event triggers when a user interacts with a search input field by pressing ENTER or clicking the "x" (clear) button. This event only works with elements and provides a convenient way to handle search operations. Syntax // Or using addEventListener element.addEventListener("search", myFunction); Example Here's how to implement the onsearch event to capture user search input: OnSearch Event Example Write what you want to search below and press "ENTER" or click the "x" to clear: ...

Read More

Join every element of an array with a specific character using for loop in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 326 Views

In JavaScript, you can join array elements with a specific character using a for loop. This approach gives you fine control over how elements are combined and what separators or wrappers to use. Problem Statement We need to create a function that takes an array and a string, then returns a new string where each array element is wrapped by the given string. For example: applyText([1, 2, 3, 4], 'a') should return 'a1a2a3a4a' Using for Loop Approach Here's how to solve this using a for loop to iterate through the array: ...

Read More

How null is converted to Number in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 10K+ Views

In JavaScript, null is a primitive value that represents the intentional absence of any object value. When null is converted to a number, it becomes 0. This article explores various methods to convert null to a number in JavaScript. Using Number() Method Using Logical OR (||) Using the ~~ operator Using Ternary Operator Using arithmetic operations Using the Number() Method The Number() method is the most straightforward way to convert null to a number. It explicitly converts null to 0. Syntax Number(null) Example ...

Read More

How to attach one or more drop-shadows to the box with JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 2K+ Views

To attach one or more drop shadows to a box with JavaScript, you can use the boxShadow style property. You can specify the shadow's horizontal offset, vertical offset, blur radius, spread radius, and color. Syntax Following is the syntax to add one or more drop shadows to the box with JavaScript: element.style.boxShadow = "offset-x offset-y blur-radius spread-radius color"; Parameters The boxShadow property accepts the following parameters: offset-x − Horizontal offset of the shadow. Positive values create a shadow on the right side, negative values on the left ...

Read More

How to return the position of the element relative to floating objects in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 559 Views

This tutorial teaches us how to return the position of the element relative to floating objects in JavaScript. To set the relative position or to get or return the relative position we are going to use the 'clear' property of JavaScript which is defined under the style property of an object. The CSS clear property controls how an element behaves next to floating elements. It can have values like 'left', 'right', 'both', or 'none'. When an element has the clear property set, it will move down to avoid overlapping with floated elements on the specified side. Syntax ...

Read More

Replace() with Split() in JavaScript to append 0 if number after comma is a single digit

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 340 Views

When working with decimal numbers as strings, you often need to format them properly. This article shows how to append a zero to single-digit numbers after a comma using JavaScript's split() and replace() methods. Problem Statement Given a string like "250, 5", we need to: Append a zero if the number after the comma is a single digit Return -1 if the string contains more than one comma Solution Using split() and replace() We can combine split() and replace() methods to achieve this: const a = "250, 5"; const roundString = (str) ...

Read More
Showing 3191–3200 of 5,340 articles
« Prev 1 318 319 320 321 322 534 Next »
Advertisements