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
How to create an Autocomplete with JavaScript?
Creating an autocomplete feature enhances user experience by providing real-time suggestions as users type. This implementation uses vanilla JavaScript to filter and display matching results from a predefined array. HTML Structure The autocomplete requires a wrapper div with the autocomplete class and an input field: Complete Example * { box-sizing: border-box; ...
Read MoreHow to disable default behavior of when you press enter with JavaScript?
To disable the default behavior when the Enter key is pressed, you need to use the keydown event listener along with preventDefault(). This prevents the browser from executing its default action for the Enter key. How It Works The preventDefault() method cancels the default action that belongs to the event. When combined with checking for the Enter key (event.key === "Enter"), it stops the browser's default behavior like form submission or input validation. Example Disable Enter Key Default ...
Read MoreJavaScript to parse and show current time stamp of an HTML audio player.
The HTML audio element provides a currentTime property that returns the current playback position in seconds. We can parse this value to display minutes and seconds separately. HTML Audio currentTime Property The currentTime property returns a floating-point number representing the current playback time in seconds. We can use Math.floor() to convert it into readable minutes and seconds format. Example Audio Timestamp Parser body { ...
Read MoreJavaScript array.includes inside nested array returning false where as searched name is in array
When working with nested arrays in JavaScript, the standard includes() method only checks the first level of the array. This article explores why this happens and provides a simple solution using JSON.stringify() to search through multidimensional arrays. The Problem The Array.prototype.includes() method only performs shallow comparison, meaning it cannot find elements nested within sub-arrays: const names = ['Ram', 'Shyam', ['Laxman', 'Jay']]; console.log(names.includes('Ram')); // true - found at first level console.log(names.includes('Laxman')); // false - nested inside sub-array true false Solution: Using JSON.stringify() A simple approach ...
Read MoreJavaScript R- eturn Array Item(s) With Largest Score
We have an array of arrays that contains the marks scored by some students in different subjects. We need to write a function that returns the top scorer(s) for each subject, handling cases where multiple students have the same highest score. Problem Setup Given this input data: const arr = [ ['Math', 'John', 100], ['Math', 'Jake', 89], ['Math', 'Amy', 93], ['Science', 'Jake', 89], ['Science', 'John', 89], ['Science', 'Amy', 83], ...
Read MoreReplace array value from a specific position in JavaScript
To replace a value at a specific position in a JavaScript array, you can use the splice() method or direct index assignment. Both approaches modify the original array. Using splice() Method The splice() method removes elements and optionally adds new ones at a specified position. Syntax array.splice(index, deleteCount, newElement) Example var changePosition = 2; var listOfNames = ['John', 'David', 'Mike', 'Sam', 'Carol']; console.log("Before replacing:"); console.log(listOfNames); var name = 'Adam'; var result = listOfNames.splice(changePosition, 1, name); console.log("After replacing:"); console.log(listOfNames); console.log("Removed element:", result); Before replacing: [ 'John', ...
Read MoreLeft right subarray sum product - JavaScript
We are required to write a JavaScript function that takes in an array of numbers of length N (N should be even) and divides the array into two sub-arrays (left and right) containing N/2 elements each, calculates the sum of each sub-array, and then multiplies both sums together. For example: If the input array is: const arr = [1, 2, 3, 4] The calculation would be: Left subarray: [1, 2] → sum = 1 + 2 = 3 Right subarray: [3, 4] → sum = 3 + 4 = 7 Product: 3 × ...
Read MoreHow to refresh a page in Firefox?
To refresh a page in a web browser like Firefox means reloading the page. It's quite easy to refresh a page using several different methods. Method 1: Using the Refresh Button Open the web page which you want to refresh. The refresh button is located on the top right corner of the Firefox web browser - it's the circular arrow icon. https://example.com ...
Read MoreHow to extend an existing JavaScript array with another array?
In this tutorial, let's find out how to extend an existing JavaScript array with another array. There are multiple methods to accomplish this task, and choosing the right one depends on whether you want to modify the original array or create a new one. Using Array push() Method with Spread Syntax The push() method adds elements to the end of an array and modifies the original array. When combined with the spread operator, it can extend an array with all elements from another array. Syntax array1.push(...array2) Example This method modifies the original ...
Read MoreHow to add properties and methods to an object in JavaScript?
In JavaScript, you can add properties and methods to objects using several approaches. The most common methods include direct assignment, using the prototype property for constructor functions, and using Object.defineProperty(). Method 1: Direct Property Assignment The simplest way to add properties to an existing object is direct assignment: Direct Property Assignment let car = { brand: "Toyota", ...
Read More