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
Set the top margin of an element with CSS
The margin-top property specifies the top margin of an element in CSS. It creates space above an element, pushing it away from adjacent elements or the container's top edge. Syntax margin-top: value; The value can be specified in pixels (px), percentages (%), em units, or set to auto for automatic margin calculation. Example CSS margin-top Example This ...
Read MoreAdd elements to a Queue using Javascript
In JavaScript, there is no built-in queue data structure like other programming languages. However, you can implement a queue using an array object and perform operations like push() to add elements at the end and shift() to remove the first element. The following diagram illustrates the queue data structure and its FIFO (First In, First Out) principle: 10 20 30 40 ...
Read MoreSafely setting object properties with dot notation strings in JavaScript
In JavaScript, safely setting nested object properties can be challenging because accessing undefined nested paths throws errors. This article covers two approaches: using Lodash's set method and creating a custom solution. Using Lodash's set() Method Lodash provides a safe set method that handles nested property assignment without throwing errors, even if intermediate properties don't exist. let _ = require("lodash"); let obj = { a: { b: { foo: "test" ...
Read MoreHow to find elements of JavaScript array by multiple values?
In JavaScript, you can find elements of an array by multiple values using various methods. The most common approaches are using filter() with includes() or checking if an array contains all elements from another array. Method 1: Using filter() with includes() This method filters an array to find elements that match any of the specified values: Find Elements by Multiple Values Find Array Elements by Multiple Values ...
Read MoreGet unique item from two different array in JavaScript
We are required to make a function that accepts an array of arrays, and returns a new array with all elements present in the original array of arrays but remove the duplicate items. For example − If the input is − const arr = [ [12, 45, 65, 76, 76, 87, 98], [54, 65, 98, 23, 78, 9, 1, 3], [87, 98, 3, 2, 123, 877, 22, 5, 23, 67] ]; Then the output should be single array of unique elements like this − ...
Read MoreHow to inherit CSS properties of parent Element using JavaScript?
JavaScript provides several ways to make child elements inherit CSS properties from their parent elements. You can use classList.add() to apply CSS classes, or directly manipulate the style property to inherit specific styles. Using classList.add() Method The most common approach is creating elements and adding CSS classes that define inheritance rules. CSS Inheritance Example .parent-container { ...
Read MoreFind the primorial of numbers - JavaScript
The primorial of a number n is equal to the product of the first n prime numbers. This is different from factorial, which multiplies consecutive integers. For example, if n = 4, we need the first 4 prime numbers: 2, 3, 5, and 7. 2 × 3 × 5 × 7 = 210 Let's write a JavaScript function that calculates the primorial of a given number. Understanding Prime Numbers First, we need a helper function to check if a number is prime: const isPrime = n => { ...
Read MoreHow to set the length of the item relative to the rest with JavaScript?
Use the flex property in JavaScript to set the length of flex items relative to each other. The flex property controls how much space a flex item should take up within a flex container. Syntax element.style.flex = "value"; The flex value can be a number (flex-grow), or a combination of flex-grow, flex-shrink, and flex-basis values. Example #box { ...
Read MoreAlign HTML5 SVG to the center of the screen
SVG stands for Scalable Vector Graphics and it is a language for describing 2D-graphics and graphical applications in XML. HTML5 provides native SVG support, and centering SVG elements on a webpage requires specific CSS techniques. Method 1: Using Auto Margins and Display Block The simplest way to center an SVG horizontally is using auto margins with display block: #svgelem { margin-left: auto; ...
Read MoreinnerHTML adds text but not HTML tags
When using innerHTML in JavaScript, you need to ensure proper HTML string formatting and correct assignment. The innerHTML property parses and renders HTML tags when set correctly. Common Issue: Building HTML Strings When concatenating HTML strings with +=, make sure to build the complete HTML structure before assigning it to innerHTML. var myNum = [1, 2, 3]; var myStr; myStr = ""; for(var a in myNum) { myStr += "" + myNum[a] + ""; } myStr += ""; document.getElementById("numberList").innerHTML = myStr; • 1 ...
Read More