Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create an Autocomplete with JavaScript?

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

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 More

How to disable default behavior of when you press enter with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 389 Views

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 More

JavaScript to parse and show current time stamp of an HTML audio player.

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

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 More

JavaScript array.includes inside nested array returning false where as searched name is in array

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

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 More

JavaScript R- eturn Array Item(s) With Largest Score

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

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 More

Replace array value from a specific position in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 581 Views

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 More

Left right subarray sum product - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 185 Views

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 More

How to refresh a page in Firefox?

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 616 Views

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 More

How to extend an existing JavaScript array with another array?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 3K+ Views

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 More

How to add properties and methods to an object in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 310 Views

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
Showing 11841–11850 of 61,303 articles
Advertisements