Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 69 of 589
JavaScript union of two objects
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 MoreJavaScript checking if all the elements are same in an array
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 MoreCall a function with onclick() – JavaScript?
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 MoreHow to find specific words in an array with JavaScript?
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 MoreHow to set a String as a key for an object - JavaScript?
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 MoreHow to sort an object in ascending order by the value of a key in JavaScript?
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 MoreJavaScript - Create an alert on clicking an HTML button
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 MoreRemoving all non-alphabetic characters from a string in JavaScript
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 MoreAdd number strings without using conversion library methods in JavaScript
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 MoreHow to set the type of positioning method used for an element with JavaScript?
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