Articles on Trending Technologies

Technical articles with clear explanations and examples

Why is using "for...in" loop in JavaScript array iteration a bad idea?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 326 Views

The for...in loop in JavaScript is designed for iterating over object properties, not array elements. Using it for arrays can lead to unexpected behavior and performance issues. Main Problems with for...in on Arrays There are several critical issues when using for...in loops with arrays: Prototype pollution: If Array.prototype is modified, for...in will iterate over inherited properties, not just array elements. No guaranteed order: for...in doesn't guarantee that array elements will be processed in numerical order. Performance overhead: The loop checks the entire prototype chain, making it slower ...

Read More

How to delete a localStorage item when the browser window/tab is closed?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 2K+ Views

To clear localStorage data when a browser window or tab is closed, you can use the beforeunload or unload events. However, there are important limitations and better alternatives to consider. Using beforeunload Event The beforeunload event fires before the page unloads, giving you a chance to clean up localStorage: window.addEventListener('beforeunload', function() { // Clear specific item localStorage.removeItem('userSession'); // Or clear all localStorage localStorage.clear(); console.log('localStorage cleared ...

Read More

How to get the value of the edit box in Selenium?

Debomita Bhattacharjee
Debomita Bhattacharjee
Updated on 15-Mar-2026 654 Views

In Selenium WebDriver, retrieving values from edit boxes (input fields) requires specific methods since getText() often returns empty strings for input elements. Here are the most effective approaches to extract values from edit boxes. Why getText() May Not Work The getText() method retrieves visible text content, but input fields store their values in the "value" attribute rather than as text content. This is why getText() often returns empty strings for input elements. Method 1: Using getAttribute("value") The most reliable approach is using the getAttribute() method to retrieve the "value" attribute: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; ...

Read More

Returning values from a constructor in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 246 Views

In JavaScript, constructors typically don't need explicit return statements since they automatically return the newly created object. However, you can override this behavior by explicitly returning an object from a constructor. How Constructor Returns Work When you use the new keyword with a constructor: If the constructor returns an object, that object becomes the result If the constructor returns a primitive value (string, number, boolean), it's ignored and this is returned instead If there's no explicit return, this is returned automatically Example: Returning an Object from Constructor ...

Read More

How do we loop through array of arrays containing objects in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 602 Views

In JavaScript, when working with nested arrays containing objects, you need to use nested loops to access each object's properties. This tutorial demonstrates multiple approaches to iterate through such complex data structures. Understanding the Data Structure An array of arrays containing objects has this structure: let arrObj = [ [ { name: "Rohan", age: 22 }, { name: "Mohan", age: 12 } ], [ ...

Read More

Order items alphabetically apart from certain words JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 184 Views

In JavaScript, you can sort an array alphabetically while keeping certain priority words at the top. This is useful when you need specific items to appear first, regardless of alphabetical order. Let's create a function excludeSort(arr, ex) where arr is the array to be sorted and ex contains the priority words that should appear at the top. How It Works The sorting logic uses a custom comparator that: Places priority words (from ex array) at the top Sorts remaining words alphabetically Uses Array.includes() to check if a word is in the priority list Example ...

Read More

Why does the JavaScript void statement evaluate an expression?

Giri Raju
Giri Raju
Updated on 15-Mar-2026 161 Views

The JavaScript void operator evaluates an expression and always returns undefined, regardless of what the expression returns. This is useful for preventing unwanted side effects in web pages. What is the void Operator? The void operator takes any expression, evaluates it, and returns undefined. It's commonly used in links to prevent navigation while still executing JavaScript code. Syntax void expression void(expression) Example: Using void(0) in Links The most common use case is void(0) in hyperlinks to prevent page navigation: Understanding JavaScript void(0) ...

Read More

How to make flexible items display in columns with JavaScript?

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

The flexFlow property in CSS controls how flexible items are arranged within a flex container. To display items in columns using JavaScript, you can modify this property dynamically. Understanding flexFlow The flexFlow property is a shorthand that combines flex-direction and flex-wrap. For column layout, use column for direction and nowrap or wrap for wrapping behavior. Example Here's how to change flexible items from row to column layout using JavaScript: #box { ...

Read More

Create editable content in an HTML document

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 891 Views

The contenteditable attribute in HTML allows users to directly edit content on a webpage. This creates interactive elements that behave like text editors within the browser. Syntax The contenteditable attribute can be applied to any HTML element: Values true - Makes the element editable by the user false - Prevents the element from being edited (default behavior) Basic Example Here's a simple demonstration of editable vs non-editable content: Editable Content Demo This content is editable. Click here ...

Read More

Chrome input type="number" CSS styling

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 1K+ Views

Chrome provides special CSS pseudo-elements to style the spinner arrows in input type="number" fields. You can hide them completely or customize their appearance. Hiding the Number Input Spinner To completely remove the spinner arrows from number inputs: input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; } input[type=number] { ...

Read More
Showing 17611–17620 of 61,297 articles
Advertisements