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
Front End Technology Articles
Page 388 of 652
Retrieve element from local storage in JavaScript?
To retrieve elements from local storage in JavaScript, we use the localStorage.getItem() method. Local storage provides persistent client-side data storage that remains available even after closing the browser. Local storage is a web API that allows you to store key-value pairs in a user's browser. Unlike session storage, data in local storage persists until explicitly removed or cleared by the user. This makes it ideal for storing user preferences, application state, or cached data. Local Storage Methods Local storage provides four main methods for data management: setItem(key, value) - Stores a key-value ...
Read MoreHow to check whether a number is finite or not in JavaScript?
In JavaScript, the isFinite() method checks whether a value is a finite number. It returns true for finite numbers and false for infinite values, NaN, or non-numeric values. Syntax isFinite(value) Parameters: value - The value to be tested for finiteness Return Value: Returns true if the value is finite, false otherwise. Example 1: Basic Usage Here's a function that demonstrates basic usage of isFinite(): Check Finite Numbers Checking division results: ...
Read MoreGetting equal or greater than number from the list of numbers in JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument. Example Following is the code − const arr = [56, 34, 2, 7, 76, 4, 45, 3, 3, 34, 23, 2, 56, 5]; const threshold = 40; const findGreater = (arr, num) => { const res = ...
Read MoreHow to encode a string in JavaScript?
In JavaScript, string encoding converts text into different formats for various purposes like URL handling, Base64 encoding, or data transmission. JavaScript provides several built-in methods for encoding strings depending on your specific needs. Encoding is the process of converting data from one format to another. Unlike encryption, encoding doesn't require keys and is primarily used to ensure data remains usable across different systems and protocols. Using btoa() Method The btoa() method encodes a string into Base64 format, which is commonly used for data transmission and storage. Syntax btoa(string) Where string is the text ...
Read MoreCreate many JavaScript objects as the same type?
In JavaScript, there are several ways to create multiple objects of the same type. JavaScript is a prototype-based object-oriented language, which means objects can inherit directly from other objects without needing traditional classes. This article explores various methods for creating objects with consistent structure and behavior. Using Constructor Functions Constructor functions are one of the most traditional ways to create multiple objects with the same structure. A constructor is simply a function that, when called with the new keyword, creates and returns a new object instance. Create many JavaScript objects as the same type ...
Read MoreHow to add a method to a JavaScript object?
In this article, we'll go over how to add a method to a JavaScript object in JavaScript with appropriate examples. A JavaScript object is an entity which has properties. A property can be a variable or a method which define state and behavior of the object. A method is a property of an object that adds behavior to an object. We can add a method to a JavaScript object using object prototype. All JavaScript objects get their attributes and methods from a prototype. Let's understand this concept better with the help of examples further in this article. ...
Read MoreAdd a property to a JavaScript object constructor?
In this article, we'll go over how to add properties to a JavaScript object constructor with appropriate examples. Adding a property to an object constructor is different from adding a property to a normal object. Properties must be added inside the constructor function itself, not outside. This ensures all instances created from the constructor have access to these properties. To get a better understanding, let's look at the syntax and usage of constructors in JavaScript. Syntax The syntax for a constructor is: function Constructor() { // No parameters } ...
Read MoreBuilt-in javascript constructors?
In this article, we are going to discuss about the Built-in JavaScript constructors with appropriate examples in JavaScript. JavaScript has provided some built-in constructors for native objects. These built-in functions include Object(), String(), Boolean(), RegExp(), Number(), Array(), Function(), and Date(). Note: We cannot include the Math object in those built-in constructors because Math is a global object. The new keyword cannot be used with Math. Let's understand this concept in a better way with the help of examples further in this article. String() Constructor The String() constructor converts values to strings. Here's an example demonstrating ...
Read MoreNumber of elements a particular tag contains in JavaScript?
In this article we are going to learn about counting the number of child elements a particular tag contains in JavaScript with suitable examples. There are two main approaches to count child elements in JavaScript. You can use the childElementCount property to count direct child elements, or use the length property with methods like getElementsByClassName() to count elements by class name. Let's explore both methods with practical examples to understand how to count elements effectively. Using the childElementCount Property The childElementCount property returns the number of direct child elements within a specific parent element. It only ...
Read MoreReplace a child node with a new node in JavaScript?
In this article we are going to learn how to replace a child node with a new node in JavaScript with suitable examples. To replace a child node with a new node, JavaScript provides two built-in DOM methods: replaceChild() and replaceWith(). Both methods allow you to swap an existing node with a new one in the DOM tree. The methods replaceChild() and replaceWith() are supported by all modern browsers and are features of the DOM specification. replaceChild() Method The replaceChild() method is called on the parent element to replace one of its child nodes. Syntax ...
Read More