Object Oriented Programming Articles

Page 192 of 589

Set JavaScript object values to null?

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

Setting object values to null can help reset data, free up memory, or show that a value is no longer needed. In JavaScript, the null value is used to indicate that there is an intentional absence of any object value. This article provides various methods for setting JavaScript object values to null and what that means. Setting an Object's Values to null Setting object values to null can be done in two types: For Specific Object Value For Multiple Object Values For Specific Object Value ...

Read More

JavaScript Remove non-duplicate characters from string

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

Non-duplicate characters in a string are those that appear only once and do not repeat within the string. Sometimes in JavaScript, we need to work with strings and manipulate them based on certain conditions. One common task is to remove characters that only appear once in a string, keeping only the characters that appear more than once. In this article, we will understand how to remove non-duplicate characters from a string in JavaScript. Understanding the Problem Suppose we have a string like "teeth_foot". We want to remove all characters that appear only once, keeping only characters that appear multiple ...

Read More

Arrays vs Set in JavaScript.

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

In this article, we will learn about the difference between an array and a set in JavaScript. Arrays are used to store ordered collections of elements, whereas Sets store only unique values in an unordered collection. What is an Array? An Array is an ordered, indexed collection of values in JavaScript. It allows duplicate values and provides various built-in methods to manipulate elements. Syntax let numbers = [1, 2, 3, 4, 5]; What is a Set? A Set is an unordered collection of unique values in JavaScript. Unlike arrays, a Set automatically ...

Read More

JavaScript reduce sum array with undefined values

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 989 Views

If you're working with arrays in JavaScript, you may encounter situations where your array contains undefined values. This can happen when you're processing data from various sources or working with incomplete datasets. One common problem developers face is summing the values of an array with undefined elements. JavaScript's reduce() method is a versatile tool that can help you solve this problem efficiently. What is the reduce() Method in JavaScript? The reduce() method in JavaScript is a powerful tool that allows you to iterate over an array and accumulate a single result. It takes a callback function as its ...

Read More

Binary Search program in JavaScript

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 871 Views

The binary search algorithm works on the divide and conquer principle as it keeps dividing the array in half before searching. To search for an element in an array using binary search, the array should be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left sub-array, right sub-array, or return the middle element. In this article, we are given a sorted array of integers, and our task is to search for the given target element ...

Read More

Adding default search text to search box in HTML with JavaScript?

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

A default search text is a text that provides suggestions or a hint of what to search for in the search (input) box. Following is an illustration of a search box, where you can observe a default search text "Search your favorite tutorials…": Search your favorite tutorials... The above default search text will suggest to visitors that they can search for their favorite tutorial, which they want to read or open on the website. HTML placeholder Attribute In HTML, the text that appears inside a ...

Read More

JavaScript variables declare outside or inside loop?

Abdul Rawoof
Abdul Rawoof
Updated on 15-Mar-2026 5K+ Views

In JavaScript, variables can be declared either inside or outside loops without performance differences. However, the choice affects variable scope and code readability. Variable Scope: var vs let With var, variables are function-scoped regardless of where declared. With let, variables are block-scoped, meaning they're only accessible within their block. Example: Variable Declared Outside Loop When declared outside, variables have broader scope and can be accessed throughout the function: function myFunction1() { var i; // Function scope - can be used throughout the function ...

Read More

What's the difference between window.location and document.location?

Abdul Rawoof
Abdul Rawoof
Updated on 15-Mar-2026 2K+ Views

In JavaScript, both window.location and document.location provide access to the current page's URL information, but they have subtle differences in browser compatibility and usage patterns. The window.location Property The window.location property is a reference to a Location object that represents the current URL of the document being displayed in that window. Since the window object is at the top of the scope chain, you can access location properties without the window prefix (e.g., location.href instead of window.location.href). Example: Getting Current URL JavaScript Get Current URL ...

Read More

How to remove the hash from window.location (URL) with JavaScript without page refresh?

Abdul Rawoof
Abdul Rawoof
Updated on 15-Mar-2026 4K+ Views

The replaceState() method replaces the current history entry with the state objects, title, and URL passed as method parameters. This method is useful when you want to update the current history entry's state object or URL in response to a user action. To remove the hash from a URL without triggering a page refresh, we can use the HTML5 History API's replaceState() method. This approach modifies the browser's address bar while keeping the user on the same page. Syntax The syntax for the replaceState() method is as follows: window.history.replaceState(stateObj, title, url) Parameters ...

Read More

Convert Image to Data URI with JavaScript

Abdul Rawoof
Abdul Rawoof
Updated on 15-Mar-2026 13K+ Views

JavaScript provides several methods to convert images to Data URI (Base64) format. A Data URI is a string representation of an image that can be embedded directly in HTML or CSS. This tutorial covers two main approaches: using Canvas API for image URLs and FileReader API for local files. Method 1: Converting Image URL to Data URI Using Canvas This method uses the HTML5 Canvas API to convert an image from a URL to a Base64 Data URI string. Convert Image URL to Data URI ...

Read More
Showing 1911–1920 of 5,881 articles
« Prev 1 190 191 192 193 194 589 Next »
Advertisements