Javascript Articles

Page 8 of 534

Call a function with onclick() – JavaScript?

Disha Verma
Disha Verma
Updated on 07-Mar-2025 4K+ Views

The onclick event is a useful feature for calling a function in JavaScript. The onclick event allows you to execute a function when a user interacts with an element, such as clicking a button. This article will guide you on how to use the onclick event to call a JavaScript function. What is Onclick Event? The onclick event is triggered when a user clicks on an HTML element. It is commonly used to execute a JavaScript function or a block of code in response to a mouse click on an HTML element, such as a button, link, or any ...

Read More

How to search a string for a pattern in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 07-Mar-2025 762 Views

Searching strings for specific patterns is a common task in JavaScript. Strings are data types and are represented as a sequence of characters. Searching patterns means verifying the presence of a specific pattern in a given string. A pattern would be a specific word, specific characters, and so on. JavaScript offers several powerful methods for pattern matching, such as inbuilt string methods and regular expressions. This article will guide you on how to search strings for specific patterns in JavaScript. Table of contents Searching strings for specific patterns in JavaScript can be done in the following ways: ...

Read More

JavaScript program to count triplets with sum smaller than a given value

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 537 Views

In this article, we will learn to count triplets with a sum smaller than a given value in JavaScript. Triplets in an array whose sum is less than a provided number is a popular problem in competitive coding and algorithm design. Problem Statement Given an array of integers and a target sum, we need to find the number of triplets (a, b, c). For exampleInput const arr = [5, 1, 3, 4, 7]; const sum = 12;Output 4 Explanation: The valid triplets are :(1, 3, 5)(1, 3, 4)(1, 4, 5)(1, 3, 7), all having a sum of less than 12. ...

Read More

JavaScript checking if all the elements are same in an array

Alshifa Hasnain
Alshifa Hasnain
Updated on 06-Mar-2025 590 Views

In this article, we will learn to check if all the elements are the same in an array in JavaScript. Finding all elements of an array to be the same is a frequent problem in JavaScript, usually needed for data validation, game logic, and algorithm building. Problem Statement We are required to write a JavaScript function that takes in an array of literals. The function should find whether or not all the values in the array are the same. If they are the same, the function should return true, or false otherwise. For Example Input const arr2 = [1, 1, ...

Read More

JavaScript focus a particular element with div class, not div id declaration?

Alshifa Hasnain
Alshifa Hasnain
Updated on 04-Mar-2025 2K+ Views

In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ...

Read More

JavaScript program to generate all rotations of a number

Alshifa Hasnain
Alshifa Hasnain
Updated on 03-Mar-2025 687 Views

In this article, we will learn to generate all rotations of a number in JavaScript. Producing a primary common problem such as all its rotations comprises the creation of all possible permutations of the digits by rotating its digits. Problem Statement The goal is that if we have given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. For exampleInput  123 Explanation  123 (original number) 231 (first rotation: move 1 to the ...

Read More

JavaScript regex program to display name to be only numbers, letters and underscore.

Alshifa Hasnain
Alshifa Hasnain
Updated on 27-Feb-2025 697 Views

In this article, we will learn the regex program to display names to be only numbers, letters, and underscores In Java. Validating user input is essential for maintaining data integrity and security in web applications.  JavaScript Regex for Name Validation Regular expressions regex is probably more powerful in defining patterns to search for in the text validations. A typical validation is confirming a name consists of only letters (A-Z, a-z), digits (0-9), and underscore (_). To ensure that a name contains only letters we can use the following regex − /^\w+$/ ^: Start of the string ...

Read More

JavaScript - Remove first n characters from string

Alshifa Hasnain
Alshifa Hasnain
Updated on 26-Feb-2025 469 Views

In this article, we will learn to calculate the union of two objects in JavaScript. The union of two objects results in a new object that contains all the properties of both objects. What is the Union of Two Objects? The union of two objects is the process of combining the properties of both objects into a single object. For example Input − const obj1 = { name: " ", email: " " }; const obj2 = { name: ['x'], email: ['y']}; Output − const output = { name: {" ", [x]}, email: {" ", [y]} }; Different Approaches ...

Read More

JavaScript union of two objects

Alshifa Hasnain
Alshifa Hasnain
Updated on 26-Feb-2025 747 Views

In this article, we will learn to calculate the union of two objects in JavaScript. The union of two objects results in a new object that contains all the properties of both objects. What is the Union of Two Objects? The union of two objects is the process of combining the properties of both objects into a single object. For example Input − const obj1 = { name: " ", email: " " }; const obj2 = { name: ['x'], email: ['y']}; Output − const output = { name: {" ", [x]}, email: {" ", [y]} }; Different Approaches ...

Read More

JavaScript ArrayBuffer Object

Alshifa Hasnain
Alshifa Hasnain
Updated on 25-Feb-2025 904 Views

In this article, we will learn about JavaScript ArrayBuffer objects. The ArrayBuffer object in JavaScript is a fundamental part of the Web API for efficiently handling binary data.  What is ArrayBuffer? The JavaScript ArrayBuffer object represents a generic, fixed-length raw binary data buffer. To manipulate the contents of an ArrayBuffer object we have to create a DataView object as we cannot manipulate the contents directly. We can read and write both using the DataView object. Syntax new ArrayBuffer(byteSize) The byteSize parameter specifies the array buffer size in bytes that will be created. Use Cases of ArrayBuffer Following are the use ...

Read More
Showing 71–80 of 5,338 articles
« Prev 1 6 7 8 9 10 534 Next »
Advertisements