Javascript Articles

Page 369 of 534

How to delete Web Storage?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 350 Views

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 More

Error codes returned in the PositionError object HTML5 Geolocation

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 480 Views

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 More

Summing numbers from a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 989 Views

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 More

Cancels ongoing watchPosition call in HTML5

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 318 Views

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 More

Finding difference of greatest and the smallest digit in a number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 435 Views

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 More

How to set focus on a text input in a list with AngularJS and HTML5

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 543 Views

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 More

Object to array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 363 Views

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 More

HTML5 tag not working in Android Webview

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 742 Views

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 More

Split number into n length array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 403 Views

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 More

What HTML5 tag should be used for filtering search results.

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 267 Views

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
Showing 3681–3690 of 5,340 articles
« Prev 1 367 368 369 370 371 534 Next »
Advertisements