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
Javascript Articles
Page 435 of 534
TextDecoder and TextEncoder in Javascript?
TextEncoder and TextDecoder are modern JavaScript APIs that handle text encoding and decoding operations. TextEncoder converts strings to UTF-8 bytes, while TextDecoder converts byte arrays back to strings with support for multiple character encodings. TextEncoder Overview TextEncoder converts JavaScript strings into UTF-8 encoded Uint8Array. It only supports UTF-8 encoding and provides a simple encode() method. TextEncoder Example ...
Read MoreCalculating average of an array in JavaScript
Calculating the average of an array is a common task in JavaScript. The average is computed by summing all elements and dividing by the array length. Basic Formula Average = (Sum of all elements) / (Number of elements) Method 1: Using forEach Loop Calculate Array Average Calculating Average of an Array Array: Calculate Average ...
Read MoreHow to convert an Image to blob using JavaScript?
Converting an image to a blob in JavaScript allows you to work with binary image data for file uploads, downloads, or processing. A blob (Binary Large Object) represents immutable binary data that can be read as text or binary data. What is a Blob? A blob is a file-like object that contains raw binary data. When you convert an image to a blob, you get access to properties like size and MIME type, making it useful for file operations. Using fetch() to Convert Image URL to Blob The most common approach is using the fetch API ...
Read MoreHow to access JavaScript properties?
In JavaScript, there are three main ways to access object properties. Each method has specific use cases and advantages depending on the situation. Three Methods to Access Properties Dot notation: object.property Square bracket notation: object['property'] Object destructuring: let {property} = object Method 1: Using Dot Notation The dot notation is the most common and readable way to access properties when the property name is known at compile time. ...
Read MoreFile and FileReader in JavaScript?
The File and FileReader APIs in JavaScript allow web applications to read and process files selected by users. The File object represents file information, while FileReader enables reading file contents asynchronously. File Object Properties When a user selects a file through an input element, you get access to a File object with these key properties: name - The file's name size - File size in bytes type - MIME type of the file lastModified - Last modification timestamp FileReader Methods FileReader provides several methods to read file contents: readAsText() - Reads ...
Read MoreFlattening multi-dimensional arrays in JavaScript
JavaScript arrays can be nested to create multi-dimensional structures. Flattening converts these nested arrays into a single-level array. The flat() method provides a clean solution for this operation. Syntax array.flat(depth) Parameters depth (optional): The number of nested levels to flatten. Default is 1. Use Infinity to flatten all levels. Basic Example Array Flattening Demo Flattening Multi-dimensional Arrays ...
Read MoreHow to create a URL object using JavaScript?
The URL object in JavaScript provides a convenient way to parse and manipulate URLs. It extracts components like protocol, host, pathname, and search parameters from URL strings. Syntax let url = new URL(urlString); let url = new URL(urlString, baseURL); Parameters urlString - The URL string to parse baseURL - (Optional) Base URL for relative URLs Example URL Object Example body { ...
Read MoreExplain shorthand functions in JavaScript?
Arrow functions, also known as shorthand functions, were introduced in ES2015 and allow us to write functions in a shorter, more concise way. They don't have their own binding to this and inherit this from the surrounding context. Basic Syntax Arrow functions use the => syntax instead of the function keyword: // Regular function function add(a, b) { return a + b; } // Arrow function const add = (a, b) => a + b; Different Arrow Function Forms ...
Read MoreHow to embed JavaScript in HTML file?
There are three main ways to embed JavaScript in an HTML file: inline scripts, internal scripts, and external scripts. Each method serves different purposes and has its own advantages. Method 1: Inline JavaScript You can add JavaScript directly to HTML elements using event attributes: Inline JavaScript Inline JavaScript Example Click Me Method 2: Internal JavaScript Use the tag within the HTML document to ...
Read MoreExplain Enumerated Types in JavaScript.
JavaScript doesn't support enums natively like other programming languages. However, you can implement enumerated types using objects to create named constants for better code readability and maintainability. Basic Enum Implementation The simplest way to create an enum is using a plain object with numeric values: JavaScript Enums Enumerated Types in JavaScript Show Color Values ...
Read More