Javascript Articles

Page 11 of 534

Converting any case to camelCase in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 30-Jan-2025 1K+ Views

In this article, we create a function that can take a string in any format. Such as normal case, snake case, pascal case or any other into camelCase in JavaScript. camelCase is a writing style where each word within a phrase is capitalized, except for the first word, and there are no spaces or punctuation. Let us understand through some sample example of I/O Scenario − Sample Input - const str = 'New STRING'; Sample Output - const output = 'newString'; Converting any case to camelCase in JavaScript Converting any case to camelCase in JavaScript is quite easy. Let's ...

Read More

Appending Suffix to Numbers in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 30-Jan-2025 1K+ Views

Appending suffixes to numbers in JavaScript is used to add ordinal indicators (like "st", "nd", "rd", and "th") to the end of a number to denote its position in a sequence. This is useful for displaying dates, rankings, or other numeric data. A custom function can be created to append the correct suffix to a given number. The function handles special cases for numbers ending in 11, 12, and 13, and applies the appropriate suffix based on the last digit for other numbers. The task of our function is to ...

Read More

Tic Tac Toe Game with HTML, CSS, and JavaScript

Souvik Chakraborty
Souvik Chakraborty
Updated on 30-Jan-2025 2K+ Views

Tic Tac Toe is well-known two square board game in which two players have to put their mark on certain spaces in turns. The player that gets three of their marks in a row either in a horizontal, vertical, or diagonal manner wins that game. If all turns are used and no player gets the line, then the draw is the end of the game. In this article, we will see how to build a Tic Tac Toe game in plain HTML, CSS, and JavaScript. The code allows a two-player mode game and additional features including the Reset button, an ...

Read More

How to Show a Word Document in an HTML Page Using JavaScript?

Souvik Chakraborty
Souvik Chakraborty
Updated on 28-Jan-2025 2K+ Views

To show a word document in an HTML page using JavaScript is important where you are required to read Word documents within your browser. This article will discuss two approaches to accomplishing this in JavaScript. They both allow you to teach your application how to load.docx files and display them on your webpage to the user. In this article, our task is to show a word document in an HTML page using JavaScript. We will be either using a .docx file from our system or using URL. Approaches to Show a Word Document in HTML Using Mammoth.js Library ...

Read More

JavaScript - Converting array of objects into object of arrays

AmitDiwan
AmitDiwan
Updated on 28-Jan-2025 1K+ Views

In this article, we will learn to convert an array of objects into an object of arrays in JavaScript. When working with JavaScript, it's common to handle arrays of objects representing structured data. A frequent challenge is grouping these objects based on a shared property and transforming the result into a new data structure. Problem Statement The goal is to convert an array of objects into an object of arrays where the keys represent a specific property (e.g., roles) and the values are arrays of corresponding data (e.g., player names). Input const team = [ { role: ...

Read More

Filter array with filter() and includes() in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 28-Jan-2025 14K+ Views

In this article, using the filter() and includes() methods in JavaScript, we can filter an array based on the elements presence in another array or specific conditions. For suppose we have two arrays as array1 and array2. we want to filter array1 to include only the elements that are present in array2. To have the clear idea about the filter() and includes() in JavaScript. Let's discuss individually. JavaScript filter() and includes() Methods filter(): It is used to create a new array that includes only the elements that satisfy the condition provided by the callback function. includes(): Using includes(), the callback ...

Read More

How to Hide a div in JavaScript on Button Click?

AmitDiwan
AmitDiwan
Updated on 27-Jan-2025 6K+ Views

To hide a div in JavaScript on button click we will be discussing three different approaches with example codes. We will hide the div upon clicking the button and similarly display the hidden div upon clicking the button. In this article we are having a div element. Our task is to hide the div on clicking the button using JavaScript. Approaches to Hide div on Button Click Here is a list of approaches to hide a div in JavaScript on button click which we will be discussing in this article with stepwise explanation and complete example codes. ...

Read More

JavaScript Program to Find the average of all positive numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 27-Jan-2025 6K+ Views

In this article, we will learn how to find the average of all positive numbers in an array using JavaScript, along with examples to demonstrate the implementation.  We are given an array of integers, which may contain both negative and positive numbers. Our task is to calculate the average of all the positive numbers in the array. Problem Description The goal is to compute the average of all positive numbers in a given array. This involves summing up the positive numbers and dividing the sum by the count of positive numbers. Input 1 arr = [2, -5, 6, -3, 8]; ...

Read More

How to Find the action Attribute and method of a Form in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 27-Jan-2025 3K+ Views

In this article we are going to learn how to find the action attribute and method of a form with suitable examples in JavaScript. In HTML, there is  elements which has few attributes: input, label, text area, select, name, target. The action and method attributes of the form are used to return those values. The action attribute also specifies where to send the form data when form is submitted. To get a better idea of this concept, let’s look into JavaScript examples where we achieved the given task using action attribute and also with method attribute. Using action ...

Read More

JavaScript program to find the average of all negative numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 22-Jan-2025 6K+ Views

In this problem, we are given an array of integers, which may contain both negative and positive numbers. We have to find the average of all the negative numbers in the array. In this article, we are going to learn how we can find the average of all negative numbers in an array using JavaScript. Example 1 Input arr = [1, -3, 4, -2, -5]; Output -3.33 Explanation The negative numbers in the array are -3, -2, and -5. Their sum is -10, and the number of negative elements is 3. The average is: -10 / 3 = -3.33. ...

Read More
Showing 101–110 of 5,338 articles
« Prev 1 9 10 11 12 13 534 Next »
Advertisements