Disha Verma

Disha Verma

45 Articles Published

Articles by Disha Verma

45 articles

JavaScript Program to Find Perimeter of a Triangle

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

The perimeter of a triangle is the sum of the lengths of its three sides. You can find the perimeter of a triangle using JavaScript by calculating the sum of all sides, where perimeter = a + b + c. To find the perimeter of a triangle using JavaScript, we need to write a function that adds the three side lengths together. In this article, we will understand the perimeter formula and implement practical examples. Understanding the Perimeter Formula The formula for the perimeter of a triangle is straightforward. The perimeter equals the sum of all three ...

Read More

JavaScript Program to Find Area and Perimeter of Rectangle

Disha Verma
Disha Verma
Updated on 15-Mar-2026 9K+ Views

To find the area and perimeter of a rectangle in JavaScript, we use the basic formulas for rectangle calculations. The area of a rectangle is the multiplication of its length by its breadth, and the perimeter is the sum of all four sides. In this article, we'll understand the formulas and implement practical JavaScript examples to calculate rectangle area and perimeter. Understanding the Formulas The formulas for rectangle calculations are straightforward: Area = length × breadth Perimeter = 2 × (length + breadth) ...

Read More

How to set a String as a key for an object - JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 6K+ Views

In JavaScript, it is common to use a string as a key for an object, especially when you want to dynamically create or change the properties of the object. Objects are fundamental data structures that allow you to store collections of data in key-value pairs. You can use strings as keys directly. It is a simple and straightforward method. This article will guide you how to use a string as a key for an object. Using Computed Property Names (ES6) The most modern approach is using computed property names with bracket notation inside the object literal. This allows ...

Read More

Call a function with onclick() – JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 4K+ Views

The onclick event is a fundamental feature for calling functions in JavaScript when users interact with HTML elements. This event allows you to execute JavaScript code in response to mouse clicks on buttons, links, or any clickable element. What is the Onclick Event? The onclick event is triggered when a user clicks on an HTML element. It's commonly used to execute JavaScript functions in response to user interactions, making web pages interactive and responsive. You can call a function using the onclick event in two main ways: Using the onclick Attribute ...

Read More

JavaScript Separate objects based on properties

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

Separating objects based on properties in JavaScript means rearranging a group of objects into a new structure where objects that share the same value for a specific property are placed together. Objects are collections of key-value pairs that store large data as a key with associated information as its value. In JavaScript, you often need to group objects inside a larger object based on certain properties. Separating objects based on properties in JavaScript can be done by writing a simple function using the reduce method. In this article, we will understand how to do this effectively. Understanding the ...

Read More

JavaScript: How to check if a number is NaN or finite?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 659 Views

Checking whether a number is NaN (Not a Number) or finite is important while working with numerical computations in JavaScript. NaN (Not a Number) indicates a value that can't be represented as a number, often occurring from invalid operations like dividing zero by zero (0/0). Finite numbers are all real numbers in JavaScript that are neither Infinity, -Infinity, nor NaN. JavaScript provides several built-in methods to determine if a value is NaN (Not a Number) or if a number is finite. In this article, you will understand how to check if a number is NaN or finite using these ...

Read More

JavaScript: Computing the average of an array after mapping each element to a value

Disha Verma
Disha Verma
Updated on 15-Mar-2026 983 Views

Computing the average of an array after mapping each element to a value in JavaScript can be done using several approaches including the forEach() loop, parseInt() method, reduce() method, and for...of loop. This article demonstrates how to calculate the average by summing all array elements and dividing by the array length. Given below are examples of arrays where we compute the average by summing values and dividing by the number of elements: Input: [1, 2, 3, 4, 5] Result: 3 Explanation: (1+2+3+4+5)/5 = 3 Input: [2, 4, 7, 9, 1, 3, 8] Result: 4.857142857142857 Explanation: (2+4+7+9+1+3+8)/7 ...

Read More

How to sort an object in ascending order by the value of a key in JavaScript?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 903 Views

Sorting an object in ascending order by the value of a key is a common task in JavaScript. Objects are data structures, which are a collection of key-value pairs. Since objects in JavaScript are unordered collections, sorting them directly is not possible. This article will guide you on how to sort an object in ascending order by the value of a key in JavaScript. Understanding the Concept Suppose we have the following object: const obj = { "sub1": 56, "sub2": 67, "sub3": 98, "sub4": ...

Read More

JavaScript: How to filter out Non-Unique Values from an Array?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

To filter out non-unique values from an array in JavaScript, you can use the filter() method, a for loop, the Set and filter() method, and the reduce() method. In this article, we will filter out non-unique values and return an array that only contains unique non-repeating elements. Arrays are data structures used to store data in a structured format. We can store the data in an array and retrieve them using their indexes. These indexes serve as a key for these values. Table of Content Filtering non-unique values from an array can be done in the following ways: ...

Read More

JavaScript: How to map array values without using \"map\" method?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 2K+ Views

When you need to transform array elements without using the built-in map() method, JavaScript provides several alternatives. These approaches manually iterate through arrays and apply transformations to create new arrays with modified values. Table of Contents You can map array values without using the map method in the following ways: Using forEach() Using reduce() Using a for Loop Using while Loop Using forEach() The forEach() method iterates through each array element, allowing you to apply transformations while manually building a ...

Read More
Showing 1–10 of 45 articles
« Prev 1 2 3 4 5 Next »
Advertisements