Object Oriented Programming Articles

Page 69 of 589

JavaScript union of two objects

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 779 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. When properties have the same key, their values are merged together. For example Input − const obj1 = { name: "John", email: "john@email.com" }; const obj2 = { name: "Jane", email: "jane@email.com" }; ...

Read More

JavaScript checking if all the elements are same in an array

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 611 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 ...

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

How to find specific words in an array with JavaScript?

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

Finding specific words in an array is a common task in JavaScript, especially when you need to filter data, search through lists, or analyze text. An array is a simple and fundamental data structure in JavaScript that stores multiple values of the same data type. JavaScript has several built-in methods, like includes(), filter(), and find(), that help you search for specific words easily. This article will explain these methods with examples. Finding Specific Words in an Array Finding specific words in an array can be done in the following ways: Using includes() ...

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

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 916 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 - Create an alert on clicking an HTML button

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 5K+ Views

In this article, we will learn to create an alert by clicking an HTML button in JavaScript. JavaScript is extensively utilized to increase user interactions on web pages. One of the widespread usage scenarios is to display an alert on a button click. What is an Alert in JavaScript? An alert is a built-in JavaScript function that displays a small pop-up or a dialogue box window containing a message. The syntax for using an alert is: alert("Your message here"); This function pauses the execution of the script until the user dismisses the alert ...

Read More

Removing all non-alphabetic characters from a string in JavaScript

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

Non-alphabetic characters are any characters that are not part of the alphabet, and the strings are a data type that represents a sequence of characters or text. Working with strings is a basic task in JavaScript, and one common task is removing all non-alphabetic characters from a string. In this article, we will understand how to remove all non-alphabetic characters from a string. Understanding the Problem Suppose we have a string saying "he@656llo wor?ld". We want to remove all digits, punctuation, whitespace, and special characters from the given string. For example: Input string we have: "he@656llo wor?ld" ...

Read More

Add number strings without using conversion library methods in JavaScript

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 307 Views

We are required to write a JavaScript program that adds two numbers represented as strings, without using any conversion library or built-in methods. For example, If the input number strings are '11' and '23', the output should be '34'. In JavaScript, a number is considered a string-represented number when the number is enclosed in single quotes ('number') or double quotes ("number"). For example: '123' or "456". If you use the typeof operator on such values, it will return the type as 'string'. Here are a few input and output scenarios that provide a better understanding of the given ...

Read More

How to set the type of positioning method used for an element with JavaScript?

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

In this tutorial, we shall learn to set the type of positioning method used for an element with JavaScript. The positioning permits us to move elements out of actual document order and make them appear in various ways. For instance, stay on top of one another or occupy the initial position within the browser viewport. Understanding CSS Position Types Before diving into JavaScript implementation, let's understand the available position values: static − The default position. Elements follow normal document flow. relative − Positioned relative to its normal position without affecting other elements. absolute − Positioned ...

Read More
Showing 681–690 of 5,881 articles
« Prev 1 67 68 69 70 71 589 Next »
Advertisements