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 can I make a browser to browser (peer to peer) connection in HTML?
Creating browser-to-browser (peer-to-peer) connections in HTML can be achieved using WebRTC technology. The PeerJS library simplifies this process by providing an easy-to-use API for establishing P2P connections. Include the PeerJS Library First, include the PeerJS library in your HTML file: Create a Peer Connection Initialize a new peer with a unique ID. PeerJS provides free public servers, so no API key is required: // Create a new peer with a unique ID var peer = new Peer('peer-' + Math.floor(Math.random() * 1000)); // Listen for incoming connections peer.on('connection', function(conn) ...
Read MoreStyle Rules in CSS
CSS comprises of style rules interpreted by the browser and then applied to the corresponding elements in your document. A style rule is made of three parts − Selector - A selector is an HTML tag at which a style will be applied. This could be any tag like or etc. Property - A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc. Value - Values assigned to properties. For ...
Read MoreHow to get all unique values in a JavaScript array?
There are multiple ways to get unique values from a JavaScript array. The most common approaches use Set, filter(), or reduce() methods. Using Set (Recommended) The Set object only stores unique values, making it the simplest approach: Unique Values with Set let arr = [2, 3, 4, 2, 3, 4, "A", "A", "B", "B"]; console.log("Original array:", ...
Read MoreJavaScript equivalent of Python\'s zip function
In this article, we will learn the JavaScript equivalent of Python's zip function. In Python, the zip() function is a convenient way to combine multiple arrays into a single iterable of tuples. However, JavaScript does not have a built-in equivalent for this functionality, so we need to implement our own. Problem Statement Given two or more arrays of equal length, implement a function in JavaScript that combines these arrays into a single array of arrays, where each inner array contains the elements from the input arrays at ...
Read MoreHow to get the maximum count of repeated letters in a string? JavaScript
We have a string that contains some repeated letters like this: const a = "fdsfjngjkdsfhhhhhhhhhhhfsdfsd"; Our job is to write a function that returns the count of maximum consecutive same letters in a streak. Like in the above string the letter 'h' appears for 11 times in a row consecutively, so our function should return 11 for this string. This problem is a good candidate for the sliding window algorithm, where a stable window contains consecutive identical letters and one that contains different elements is unstable. The window adjusts by moving the start pointer when different characters ...
Read MoreHow to put variable in regular expression match with JavaScript?
You can put a variable in a regular expression match by using the RegExp constructor, which accepts variables as patterns. This is essential when you need dynamic pattern matching in JavaScript. Syntax // Using RegExp constructor with variable let pattern = new RegExp(variableName, flags); string.match(pattern); // Or directly with match() string.match(variableName); // for simple string matching Example: Using Variable in Regular Expression let sentence = 'My Name is John'; console.log("The actual value:"); console.log(sentence); let matchWord = 'John'; console.log("The matching value:"); console.log(matchWord); // Using RegExp constructor with variable let matchRegularExpression = ...
Read MoreRepeat even number inside the same array - JavaScript
We are required to write a JavaScript function that should repeat the even number inside the same array. Therefore, for example given the following array − const arr = [1, 2, 5, 6, 8]; We should get the output − const output = [1, 2, 2, 5, 6, 6, 8, 8]; Example Following is the code − const arr = [1, 2, 5, 6, 8]; const repeatEvenNumbers = arr => { let end = arr.length - 1; for(let i = ...
Read MoreHow to set named cookies in JavaScript?
To set named cookies in JavaScript, use document.cookie with the format name=value. Named cookies allow you to store multiple key-value pairs that can be retrieved later. Basic Syntax document.cookie = "cookieName=cookieValue; expires=date; path=/"; Example: Setting a Customer Name Cookie function WriteCookie() { if (document.myform.customer.value == "") { alert("Enter some ...
Read MoreHow to preselect Dropdown Using JavaScript Programmatically?
In this tutorial, we will learn how to preselect dropdown options using JavaScript programmatically. This is useful when you want to set default selections based on user preferences, data from APIs, or other dynamic conditions. A dropdown list is a toggle menu that allows users to select one option from multiple choices. In HTML, dropdown lists are created using the element combined with elements. JavaScript provides several methods to programmatically control these selections. There are two primary methods to preselect dropdown options: using the selectedIndex property and using the value property. Let's explore both approaches. ...
Read MoreHow to catch exceptions in JavaScript?
To catch exceptions in JavaScript, use try...catch...finally. JavaScript implements the try...catch...finally construct as well as the throw operator to handle exceptions. You can catch programmer-generated and runtime exceptions, but you cannot catch JavaScript syntax errors. Syntax try { // Code that may throw an exception } catch (error) { // Handle the exception } finally { // Optional - always executes } Example: Basic Exception Handling Here's a simple example demonstrating exception catching: ...
Read More