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 369 of 534
How to delete Web Storage?
Web Storage provides methods to delete stored data from both Local Storage and Session Storage. Understanding how to properly clear this data is essential for maintaining user privacy and managing storage space effectively. Removing Individual Items To delete a specific item from storage, use the removeItem() method with the key name: // Store some data first localStorage.setItem('username', 'john'); localStorage.setItem('theme', 'dark'); ...
Read MoreError codes returned in the PositionError object HTML5 Geolocation
The HTML5 Geolocation API returns specific error codes through the PositionError object when location requests fail. Understanding these codes helps you handle different error scenarios appropriately. Error Codes Reference The following table describes the possible error codes returned in the PositionError object: Code Constant Description ...
Read MoreSumming numbers from a string - JavaScript
We are required to write a JavaScript function that takes in a string that contains some one-digit numbers in between and the function should return the sum of all the numbers present in the string. Let's say the following is our string with numbers: const str = 'gdf5jhhj3hbj4hbj3jbb4bbjj3jb5bjjb5bj3'; Method 1: Using for Loop with Type Conversion This approach splits the string into characters and checks each one using type conversion: const str = 'gdf5jhhj3hbj4hbj3jbb4bbjj3jb5bjjb5bj3'; const sumStringNum = str => { const strArr = str.split(""); let ...
Read MoreCancels ongoing watchPosition call in HTML5
The clearWatch method cancels an ongoing watchPosition call. When canceled, the watchPosition call stops retrieving updates about the current geographic location of the device. Syntax navigator.geolocation.clearWatch(watchID); Parameters The clearWatch method takes one parameter: watchID: The ID returned by watchPosition() that identifies the watch operation to cancel Example: Watch and Stop Location Updates var watchID; ...
Read MoreFinding difference of greatest and the smallest digit in a number - JavaScript
We are required to write a JavaScript function that takes in a number and returns the difference between the greatest and the smallest digit present in it. For example: If the number is 5464676, then the smallest digit here is 4 and the greatest is 7 Hence, our output should be 3 Example Let's write the code for this function — const num = 44353456; const difference = (num, min = Infinity, max = -Infinity) => { if(num){ const digit = num ...
Read MoreHow to set focus on a text input in a list with AngularJS and HTML5
To set focus on a text input in a list with AngularJS, you need to create a custom directive that observes a focus attribute and programmatically sets focus when the condition is met. Creating the Focus Directive First, create a custom directive that will handle the focus functionality: Focus state: {{cue.isNewest}} ...
Read MoreObject to array - JavaScript
Converting an object to an array of key-value pairs is a common task in JavaScript. There are several built-in methods to achieve this transformation. Sample Object Let's start with this example object: const obj = { name: "Vikas", age: 45, occupation: "Frontend Developer", address: "Tilak Nagar, New Delhi", experience: 23, salary: "98000" }; Using Object.entries() (Recommended) The simplest approach is using Object.entries(), which directly converts an object to an ...
Read MoreHTML5 tag not working in Android Webview
When HTML5 audio/video tags don't work in Android WebView, you can bridge JavaScript with native Android MediaPlayer functionality. This approach allows HTML content to trigger native audio playback through JavaScript interfaces. Setting Up JavaScript Interface First, create a WebView with a JavaScript interface that exposes Android's MediaPlayer to your HTML content: WebView wv = (WebView) findViewById(R.id.webview); wv.getSettings().setJavaScriptEnabled(true); wv.addJavascriptInterface(new WebAppInterface(this), "Android"); public class WebAppInterface { Context mContext; MediaPlayer mediaPlayer; WebAppInterface(Context c) { ...
Read MoreSplit number into n length array - JavaScript
We are required to write a JavaScript function that takes in two numbers say m and n, and returns an array of size n with all the elements of the resulting array adding up to m. Let's write the code for this function − Example Following is the code − const len = 8; const sum = 5; const splitNumber = (len, sum) => { const res = []; for(let i = 0; i < len; i++){ res.push(sum / ...
Read MoreWhat HTML5 tag should be used for filtering search results.
HTML5 provides semantic elements for organizing content, but there's no specific tag exclusively for filtering search results. The best approach is to use a combination of semantic elements with appropriate roles and structure. Recommended Structure for Search Filters Use the element with filter controls inside a for better semantics and accessibility: Search Results Filter Results ...
Read More