Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript code to extract the words in quotations

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

Extracting text enclosed in quotation marks is a common task in programming, especially when working with strings that include quotes. In JavaScript, strings are a data type used to represent text. A string is a sequence of characters enclosed in single quotes ('), double quotes ("), or backticks (`). JavaScript provides multiple ways to extract text enclosed in quotation marks. This article explains how to extract words or phrases inside quotations from a string efficiently using different approaches. Methods to Extract Quoted Text Extracting text enclosed in quotation marks can be done in the following ways: ...

Read More

What is this problem in JavaScript's selfexecuting anonymous function?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 234 Views

Let's analyze this JavaScript code snippet that demonstrates a common confusion with variable hoisting and function declarations in self-executing anonymous functions. var name = 'Zakir'; (() => { name = 'Rahul'; return; console.log(name); function name(){ let lastName = 'Singh'; } })(); console.log(name); Naive Analysis (Incorrect) At first glance, you might expect this sequence: Global variable name is set to 'Zakir' Inside the IIFE, name is ...

Read More

How to count the number of elements in an array below/above a given number (JavaScript)

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 267 Views

In JavaScript, we often need to analyze arrays and count elements based on certain conditions. This article shows how to count array elements that fall below or above a given threshold number. Consider we have an array of numbers like this: const array = [3.1, 1, 2.2, 5.1, 6, 7.3, 2.1, 9]; We need to write a function that counts how many elements are below and above a given number. For example, if the number is 5.25, there should be 5 elements below it: (3.1, 1, 2.2, 5.1, 2.1) And ...

Read More

Is there a DOM function which deletes all elements between two elements in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 374 Views

In JavaScript, there's no single DOM function that directly deletes all elements between two elements. However, you can achieve this using a combination of DOM methods like nextElementSibling and remove(). Problem Setup Consider the following HTML structure where we want to remove all elements between a starting point and an ending point: START My Name is John My Name is David My Name is Bob My Name is Mike My Name is Carol END We need to remove all elements between the (START) and (END) elements. Solution Using nextElementSibling ...

Read More

Twice repetitive word count in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We are required to write a JavaScript function that takes in a string that contains some words that are repeated twice, we need to count such words. For example, if the input string is: const str = "car bus jeep car jeep bus motorbike truck"; Then the output should be: 3 The function counts words that appear more than once in the string. In this case, "car", "bus", and "jeep" each appear twice. Using Array Methods Here's a solution that splits the string into words and counts duplicates: ...

Read More

Writing a For Loop to Evaluate a Factorial - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We are required to write a simple JavaScript function that takes in a Number, say n and computes its factorial using a for loop and returns the factorial. For example: factorial(5) = 120, factorial(6) = 720 The approach is to maintain a count and a result variable, keep multiplying the count into result, simultaneously decreasing the count by 1, until it reaches 1. Then finally we return the result. Syntax function factorial(n) { let result = 1; for (let i = n; i > ...

Read More

How to create an array of integers in JavaScript?

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

In this article, we will learn to create an array of integers in JavaScript. The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4, 294, 967, 295. Different Approaches The following are the two different approaches to creating an array of integers in JavaScript − Using Array Literals Using the Array Constructor Using Array Literals One of ...

Read More

How to return which part of a positioned element is visible in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 291 Views

This tutorial teaches us how to return which part of a positioned element is visible in JavaScript. A positioned element is an HTML element with CSS positioning (absolute, relative, fixed, etc.). To make only a defined part visible, we use the CSS clip property to hide unwanted areas. The clip property defines a rectangular clipping region that determines which portion of an absolutely positioned element should be visible. Syntax Here's the basic syntax for clipping an element and retrieving the clip value: document.getElementById("elementId").style.clip = "rect(top right bottom left)"; let clipValue = document.getElementById("elementId").style.clip; The ...

Read More

How to reconnect to websocket after close connection with HTML?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 5K+ Views

WebSockets are designed to maintain persistent connections, but they can close due to network issues, server restarts, or connection timeouts. When a WebSocket connection closes, you need to manually recreate the socket to reconnect. How WebSocket Reconnection Works When a WebSocket connection closes, the onclose event fires. You can handle this event to automatically attempt reconnection by creating a new WebSocket instance and reattaching event listeners. Basic Reconnection Example // Socket Variable declaration var mySocket; const socketMessageListener = (event) => { console.log('Received:', event.data); }; // Connection opened const ...

Read More

How to make iOS UIWebView display a mobile website correctly?

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

To make iOS UIWebView display mobile websites correctly, you need to configure both the webview properties and viewport settings. Here are the most effective approaches: Method 1: Using scalesPageToFit Property The primary solution is enabling automatic scaling in your UIWebView: mywebview.scalesPageToFit = YES; mywebview.contentMode = UIViewContentModeScaleAspectFit; This allows the webview to automatically scale content to fit the device screen width. Method 2: JavaScript Zoom Control For fine-tuned control, inject JavaScript to adjust the zoom level: NSString *js = [NSString stringWithFormat:@"document.body.style.zoom = 0.8;"]; [webView stringByEvaluatingJavaScriptFromString:js]; Method 3: Viewport Meta ...

Read More
Showing 16911–16920 of 61,297 articles
Advertisements