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 add video to site background in HTML 5?
HTML5's element allows you to create stunning background videos that automatically play and loop behind your content. This technique is commonly used for modern, engaging websites. HTML Structure The basic HTML structure requires a video element with specific attributes for background functionality: #myVideo { position: fixed; right: 0; ...
Read MoreCreating 'Copy to Clipboard' feature on a web page with JavaScript
The copy to clipboard feature allows users to easily copy text from input fields or other elements on a webpage. This functionality is essential for improving user experience in web applications. Modern Approach Using Clipboard API The modern way to implement copy to clipboard uses the Clipboard API, which is more secure and reliable than the deprecated execCommand method. Copy to Clipboard body { ...
Read MoreHow to multiply odd index values JavaScript
We are required to write a function that takes in an array of Number literals as one and the only argument. The numbers that are situated at even index should be returned as it is. But the numbers situated at the odd index should be returned multiplied by their corresponding indices. For example: If the input is: [5, 10, 15, 20, 25, 30, 50, 100] Then the function should return: [5, 10, 15, 60, 25, 150, 50, 700] Understanding the Logic Let's break down what happens at each ...
Read MoreSolve the Sherlock and Array problem in JavaScript
Watson gives Sherlock an array A of length N. Then he asks him to determine if there exists an element in the array such that the sum of the elements on its left is equal to the sum of the elements on its right. We have to write this function, it should take in an array of Numbers, and any such number exists in the array, it should return its index, otherwise it should return -1. So, let's write the code for this function. Algorithm Approach The efficient approach is to: Calculate the total sum of ...
Read MoreCounting elements of an array using a recursive function in JS?
A recursive function calls itself until a base condition is met. In JavaScript, we can use recursion to count array elements by reducing the array size in each recursive call. How Recursive Counting Works The recursive approach works by: Base case: If array is empty, return 0 Recursive case: Return 1 + count of remaining elements Example function countNumberOfElementsUsingRecursive(listOfMarks) { if (listOfMarks.length == 0) { return 0; } return 1 + countNumberOfElementsUsingRecursive(listOfMarks.slice(1)); } ...
Read MoreCompare array of objects - JavaScript
We have two arrays of objects like these: const blocks = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, ] const containers = [ { block: { id: 1 } }, { block: { id: 2 } }, { block: { id: 3 } }, ] We are required to write a function that checks each object of blocks array with the block key of each ...
Read MoreHow can I pop-up a print dialog box using JavaScript?
To pop-up a print dialog box using JavaScript, use the window.print() method. This method opens the browser's print dialog, allowing users to select printing options like printer choice, page range, and paper size. Syntax window.print(); Basic Example Here's a simple example that opens the print dialog when a button is clicked: Print Dialog Example My Document This content will be printed when you click the print button. ...
Read MoreGenerating sound on the fly with JavaScript/ HTML5
The Web Audio API is used to control audio, which allows you to choose audio sources. You can also add effects, create audio visualizations, panning, and generate sounds programmatically in web browsers. Basic Sound Generation To generate sound with the Web Audio API, you need three main components: an AudioContext, an oscillator (sound source), and a destination (speakers). Here's how to create a simple tone: Generate Sound Play 500Hz Tone ...
Read MoreHow to convert a JSON string into a JavaScript object?
JSON (JavaScript Object Notation) is a lightweight data format commonly used for data exchange between servers and web applications. When receiving data from a server, it typically arrives as a JSON string that needs to be converted into a JavaScript object to be usable in your code. Why JSON.parse() Over eval() There are two possible ways to convert a JSON string into a JavaScript object: eval() and JSON.parse(). However, eval() is unsafe and vulnerable to code injection attacks, making it unsuitable for parsing JSON data. JSON.parse() is the recommended and secure method. Syntax JSON.parse(text[, reviver]) ...
Read MoreThe generator.throw() method in JavaScript.
The generator.throw() method allows you to inject an error into a generator function at the current yield point. When called, it throws the specified error inside the generator and returns an object with done and value properties. Syntax generator.throw(exception) Parameters exception: The error object to be thrown inside the generator function. Basic Example function* simpleGenerator() { try { console.log("Before first yield"); yield 1; ...
Read More