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
Web Development Articles
Page 423 of 801
ImplementJavaScript Auto Complete / Suggestion feature
JavaScript's auto-complete feature helps users by suggesting matching options as they type. This improves user experience and reduces typing errors. We can implement this using HTML5's datalist element combined with JavaScript for dynamic filtering. Understanding the HTML Structure The foundation uses an input field linked to a datalist element. The datalist contains predefined options that appear as suggestions: Complete Implementation body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; ...
Read MoreCheck if some elements of array are equal JavaScript
We have an array of numbers that have got some redundant entries, our job is to write a function that takes in the array and groups all the identical entries into one subarray and returns the new array thus formed. For example − //If the input array is: const arr = [1, 3, 3, 1]; //then the output should be: const output = [[1, 1], [3, 3]]; We will use a HashMap to keep a track of the elements already occurred and iterate over the array using a for loop. Using HashMap Approach ...
Read MoreHow do I recursively remove consecutive duplicate elements from an array?
Suppose, we have an array of Number literals that contains some consecutive redundant entries like this: const testArr = [1, 1, 2, 2, 3, 3, 1, 1, 1]; We are supposed to write a function compress that takes in this array and removes all redundant consecutive entries in place. So that the output looks like this: const output = [1, 2, 3, 1]; Let's write the code for this function using recursion to remove consecutive duplicate elements. Recursive Approach The recursive function works by traversing the array and comparing each ...
Read MoreJavaScript - Get the text of a span element
In JavaScript, you can get the text content of a span element using several methods. The most common approaches are innerHTML, textContent, and innerText. Methods to Get Span Text There are three main properties to retrieve text from a span element: innerHTML - Gets HTML content including tags textContent - Gets plain text content (recommended) innerText - Gets visible text content Example: Getting Span Text Get Span Text ...
Read MoreJavaScript global Property
The global property in JavaScript returns true or false depending on whether the 'g' (global) modifier is set in a regular expression pattern. Syntax regexPattern.global Return Value Returns a boolean value: true - if the 'g' flag is set false - if the 'g' flag is not set Example: Checking Global Flag JavaScript Global Property JavaScript Global Property Example ...
Read MoreCheck whether a series of operations yields a given number with JavaScript Recursion
By starting from the number 1 and repeatedly either adding 5 or multiplying by 3, an infinite amount of new numbers can be produced. We are required to write a function that, given a number, tries to find a sequence of such additions and multiplications that produce that number. And returns a boolean based on the fact whether or not there exists any such sequence. For example, the number 13 could be reached by first multiplying by 3 and then adding 5 twice (1 × 3 = 3, 3 + 5 = 8, 8 + 5 = 13), so ...
Read MoreJavaScript Immediately Invoked Function Expressions (IIFE)
An Immediately Invoked Function Expression (IIFE) is a JavaScript function that executes immediately after it has been defined. This pattern is useful for creating isolated scope and avoiding global namespace pollution. Syntax (function() { // Code here runs immediately })(); // Alternative syntax (function() { // Code here runs immediately }()); Basic IIFE Example IIFE Example JavaScript IIFE Demo ...
Read MoreJavaScript JSON Arrays
JSON arrays are ordered lists of values enclosed in square brackets. In JavaScript, you can access and manipulate JSON arrays just like regular JavaScript arrays. Syntax { "arrayName": ["value1", "value2", "value3"] } Basic JSON Array Structure Here's how a JSON object with an array property looks: JSON Array Example let obj = { ...
Read MoreChanging an array in place using splice() JavaScript
The splice() method allows you to modify arrays in place by removing, adding, or replacing elements. This article demonstrates how to use splice() to remove duplicate elements that exceed a specified count limit. The Problem We need to write a function that takes an array and a number n, then removes elements that appear more than n times while preserving the order of remaining elements. Solution Using splice() We'll track element counts using a hashmap and use splice() to remove excess occurrences during iteration: const arr = [7, 26, 21, 41, 43, 2, 26, ...
Read MoreJavaScript JSON HTML
Generating HTML from JSON data is a common task in web development. You can fetch JSON data from APIs and dynamically create HTML elements to display the information. Note − JSONPlaceholder is a fake Online REST API for Testing and Prototyping. Example: Creating HTML Table from JSON JSON to HTML Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...
Read More