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
Creating a JavaScript Object from Single Array and Defining the Key Value?
JavaScript provides several ways to create objects from arrays and define key-value pairs. This is useful when transforming data structures or converting between different formats. Using Object.entries() with map() The most common approach uses Object.entries() to convert an object into an array of key-value pairs, then map() to transform the structure: var studentObject = { 101: "John", 102: "David", 103: "Bob" }; var studentDetails = Object.entries(studentObject).map(([studentId, studentName]) => ({ studentId, studentName })); console.log(studentDetails); ...
Read MoreTake two numbers m and n & return two numbers whose sum is n and product m in JavaScript
We need to write a JavaScript function that takes two numbers m (product) and n (sum) and returns two numbers whose sum equals n and product equals m. If no such numbers exist, the function should return false. This is essentially solving a quadratic equation where we need to find two numbers x and y such that x + y = n and x × y = m. Mathematical Approach We can solve this using the quadratic formula. If x + y = n and x × y = m, then x and y are roots of ...
Read MoreHow to search and display the pathname part of the href attribute of an area with JavaScript?
To get the pathname part of the href attribute of an area in JavaScript, use the pathname property. This property extracts just the path portion from a URL, excluding the protocol, domain, and query parameters. Syntax areaElement.pathname Example You can try to run the following code to display the pathname part of an area element's href attribute. ...
Read MoreHow to change date time format in HTML5?
HTML5 provides several input types for date and time, but formatting them requires JavaScript. The default browser format can be customized using JavaScript date methods or libraries. HTML5 Date Input Types HTML5 offers various date and time input types: Basic Date Formatting with JavaScript You can format dates using JavaScript's built-in methods: const dateInput = document.getElementById('dateInput'); const output = document.getElementById('output'); dateInput.addEventListener('change', function() { const date = new Date(this.value); ...
Read MoreWorking with element for CSS
You can put your CSS rules into an HTML document using the element. This tag is placed inside ... tags. Rules defined using this syntax will be applied to all the elements available in the document. Syntax /* CSS rules go here */ selector { property: value; } Example Following is an example of embedded CSS ...
Read MoreCalculating median of an array in JavaScript
In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the Problem The problem statement is to write a function in Javascript that will help to calculate the median of a given array. The median is the middle value when numbers are arranged in ascending order. For example: Array [1, 2, 3, 4, 5] has median 3 (middle element) Array ...
Read MoreFrom an array of arrays, return an array where each item is the sum of all the items in the corresponding subarray in JavaScript
Given an array of arrays, each of which contains a set of numbers. We have to write a function that returns an array where each item is the sum of all the items in the corresponding subarray. For example, if we have nested arrays with numbers, we want to calculate the sum of each inner array and return those sums as a new array. Example Input and Expected Output If the input array is: const numbers = [ [1, 2, 3, 4], [5, 6, 7], [8, ...
Read MoreHow to add hours and minutes to a date with JavaScript?
In this tutorial, we will learn how to add hours and minutes to a date with JavaScript. We have multiple methods to achieve this which are the following. Add hours using the setHours() Method. Add minutes using the setMinutes() Method. Add hours or minutes with the getTime() Method. Add hours using the setHours Method JavaScript date setHours() method sets the hours for a specified date according to local time. Syntax Following is the syntax to apply the setHours() method to add ...
Read MoreHow to set all the background properties in one declaration with JavaScript DOM?
To set multiple background properties in JavaScript, use the background property. This shorthand property allows you to set background color, image, position, repeat, and other background-related properties in a single declaration. Syntax element.style.background = "color image repeat attachment position"; Background Property Values The background shorthand can include the following properties in any order: background-color: Sets the background color background-image: Sets the background image using url() background-repeat: Controls image repetition (repeat, no-repeat, repeat-x, repeat-y) background-position: Sets image position (left, right, center, top, bottom, or pixel values) background-attachment: Controls scrolling behavior (scroll, fixed) ...
Read MoreCreate JS Radial gradient with matrix in HTML
JavaScript radial gradients with matrix transformations allow you to create scaled and transformed gradient effects on HTML canvas elements. This technique combines gradient creation with matrix scaling operations. HTML Structure First, create a canvas element with CSS styling: canvas { background-color: purple; border: 1px solid #ccc; } Creating Radial Gradient with Matrix Here's how to create a radial gradient with matrix scaling applied: // Get canvas and 2D context var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); // ...
Read More