Object Oriented Programming Articles

Page 187 of 589

How to enable a strict mode in javascript?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 179 Views

In JavaScript, there are two different programming paradigms. The sloppy mode, sometimes referred to as the simple mode, is activated by default. We don't have to write the code strictly according to guidelines in this manner. On the other side, there is also the strict mode. This setting allows the environment to have some rigid constraints. Strict mode has different semantics than regular code and is not a subset of sloppy mode. This article will explain how to enable strict mode in JavaScript and will also go over some of the features of "Strict" Mode. Syntax Different scopes ...

Read More

Calculating median of an array in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 4K+ Views

In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the Problem The problem statement is to write a function in Javascript that will help to calculate the median of a given array. The median is the middle value when numbers are arranged in ascending order. For example: Array [1, 2, 3, 4, 5] has median 3 (middle element) Array ...

Read More

Find number of spaces in a string using JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 3K+ Views

In JavaScript, counting spaces in a string is a common task that can be accomplished using several built-in methods. This article explores different approaches to find the number of space characters in a string. Problem Overview Given a string with space characters, we need to count how many spaces it contains. For example, the string "Hello world example" contains 2 spaces. const exampleString = "This is an example of counting spaces"; // Expected output: 6 spaces Method 1: Using split() Method The split() method divides a string into an array based on a ...

Read More

How to find distance between items on array JavaScript?

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

In JavaScript, finding the distance between array items means calculating how many positions separate two elements. The distance is measured as the absolute difference between their index positions. Understanding the Problem Array distance represents the number of steps needed to move from one element to another. For example, in the array [1, 2, 3, 4, 5], the distance between elements 2 and 4 is 2 because their indices are 1 and 3 respectively, giving us |3 - 1| = 2. Basic Distance Calculation The simplest approach uses indexOf() to find element positions and calculates the absolute ...

Read More

How to add an element to a JavaScript object?

Vivek Verma
Vivek Verma
Updated on 15-Mar-2026 75K+ Views

In JavaScript, objects are real-time entities that contain properties and methods. Objects store data in key-value pairs, where keys are called properties and values are called property values. There are multiple ways to add new properties to existing JavaScript objects. Let's explore the most common approaches. Object Creation Syntax var obj = new Object(); Or using object literal syntax: var obj = {property1: value1, property2: value2}; Using Dot (.) Operator The dot operator is the most common way to add properties to JavaScript objects. It acts as a connector ...

Read More

How to read data from *.CSV file using JavaScript?

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 41K+ Views

In this article, we are going to learn how to read data from *.CSV file using JavaScript. To convert or parse CSV data into an array, we need JavaScript's FileReader class, which contains a method called readAsText() that will read a CSV file content and parse the results as string text. If we have the string, we can create a custom function to turn the string into an array. To read a CSV file, first we need to accept the file. Now let's see how to accept the csv file from browser using HTML elements. ...

Read More

How to import local json file data to my JavaScript variable?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 34K+ Views

When working with local JSON files in JavaScript, you need to import the data into your JavaScript variables. This article demonstrates how to load JSON data from a local file using different methods depending on your environment. Let's say we have an employees.json file in our project directory: Sample JSON File employees.json { "Employees": [ { "userId": "ravjy", "jobTitleName": "Developer", "firstName": "Ran", "lastName": "Vijay", ...

Read More

Enter key press event in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 27K+ Views

The Enter key press event in JavaScript allows you to detect when users press the Enter key (keycode 13) and execute specific functions. This is commonly used for form submissions, search functionality, or triggering actions without clicking a button. Basic Syntax You can handle the Enter key using the onkeypress event handler: onkeypress="yourFunctionName(event)" The Enter key has a keycode of 13, which you can check using event.keyCode. Method 1: Using onkeypress Attribute Enter Key ...

Read More

JavaScript function to take a number n and generate an array with first n prime numbers

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop ...

Read More

JavaScript how to get an alert to appear when I click on a button in a class?

Shriansh Kumar
Shriansh Kumar
Updated on 15-Mar-2026 2K+ Views

An alert in JavaScript is a dialog box that displays important information or warnings to the user. It contains a message with an OK button that dismisses the dialog when clicked. Clicking a button triggers an event handler that invokes a function instructing the browser to display the alert dialog. In this article, we will explore different ways to show an alert when a user clicks on a button in a class. For example, click on the button below to see an alert: .alerttoappear { margin: auto; width: ...

Read More
Showing 1861–1870 of 5,881 articles
« Prev 1 185 186 187 188 189 589 Next »
Advertisements