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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Why is using "for...in" loop in JavaScript array iteration a bad idea?
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 MoreHow to delete a localStorage item when the browser window/tab is closed?
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 MoreHow to get the value of the edit box in Selenium?
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 MoreReturning values from a constructor in JavaScript?
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 MoreHow do we loop through array of arrays containing objects in JavaScript?
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 MoreOrder items alphabetically apart from certain words JavaScript
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 MoreWhy does the JavaScript void statement evaluate an expression?
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 MoreHow to make flexible items display in columns with JavaScript?
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 MoreCreate editable content in an HTML document
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 MoreChrome input type="number" CSS styling
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