Articles on Trending Technologies

Technical articles with clear explanations and examples

CSS padding property

Samual Sam
Samual Sam
Updated on 15-Mar-2026 231 Views

The padding property sets the internal space between an element's content and its border. It creates space inside the element on all four sides: top, right, bottom, and left. Syntax padding: value; padding: top-bottom left-right; padding: top left-right bottom; padding: top right bottom left; Padding Values The padding property accepts various units: px - Fixed pixels % - Percentage of parent element's width em/rem - Relative to font size auto - Browser calculates automatically Examples Single Value (All Sides) ...

Read More

Get the first and last item in an array using JavaScript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 371 Views

JavaScript arrays are 0-indexed, meaning the first element is at position 0 and the last element is at position length - 1. Here are several ways to access the first and last elements of an array. Using Index Access The most straightforward method uses bracket notation with index positions: let arr = [1, 'test', {}, 'hello', 42]; // First element console.log("First element:", arr[0]); // Last element console.log("Last element:", arr[arr.length - 1]); First element: 1 Last element: 42 Using Array Methods JavaScript provides built-in methods for accessing ...

Read More

How to create a responsive slideshow with CSS and JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 3K+ Views

In this article, we will create a responsive slideshow using JavaScript and CSS. A responsive slideshow is an interactive design element that displays a series of images with navigation controls, adapting to different screen sizes. A responsive slideshow allows users to browse through multiple images using arrow buttons or dot indicators. It's commonly used to showcase content while conserving space on web pages. HTML Structure First, create the HTML structure with a container for slides, navigation arrows, and dot indicators: 1 / 3 ...

Read More

JavaScript - know the value of GET parameters from URL

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 293 Views

To extract GET parameters from a URL in JavaScript, you can use the built-in URL and URLSearchParams APIs. These provide a clean way to parse query strings from URLs. Using URL and URLSearchParams The URL constructor creates a URL object, and its searchParams property gives access to query parameters: GET Parameters Example body { ...

Read More

How to check whether a Button is clicked with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In JavaScript, you can detect button clicks using event listeners. The addEventListener() method is the standard approach to handle click events and track user interactions. Basic Click Detection The most common way to check if a button is clicked is using the click event: Button Click Detection body { font-family: "Segoe UI", Tahoma, Geneva, ...

Read More

Fix Problem with .sort() method in JavaScript, two arrays sort instead of only one

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 298 Views

One property of the Array.prototype.sort() function is that it is an in-place sorting algorithm, which means it does not create a new copy of the array to be sorted, it sorts the array without using any extra space, making it more efficient and performant. But this characteristic sometimes leads to an awkward situation. Let's understand this with an example. Assume, we have a names array with some string literals. We want to keep the order of this array intact and want another array containing the same elements as the names array but sorted alphabetically. We can do something ...

Read More

Rearrange an array in maximum minimum form by JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 328 Views

We are required to write a function, say minMax() that takes in an array of Numbers and rearranges the elements such that the greatest element appears first followed by the smallest elements then the second greatest element followed by second smallest element and so on. For example − // if the input array is: const input = [1, 2, 3, 4, 5, 6, 7] // then the output should be: const output = [7, 1, 6, 2, 5, 3, 4] So, let's write the complete code for this function − Approach: Using Two Pointers ...

Read More

Copy objects with Object.assign() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 242 Views

The Object.assign() method is used to copy one or more source objects to a target object. It invokes getters and setters since it uses both 'get' on the source and 'set' on the target. Syntax Object.assign(target, ...sourceObjects); The first parameter is the target object that will be modified and returned. The remaining parameters are source objects whose properties will be copied to the target. Basic Example const target = { a: 1, b: 2 }; const source = { b: 3, c: 4 }; const result = Object.assign(target, source); console.log("Target ...

Read More

Diagonal product of a matrix - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

Suppose, we have a 2-D array representing a square matrix like this − const arr = [ [1, 3, 4, 2], [4, 5, 3, 5], [5, 2, 6, 4], [8, 2, 9, 3] ]; We are required to write a function that takes in this array and returns the product of the elements present at the principal diagonal of the matrix. Principal Diagonal Elements The principal diagonal consists of elements where the row index equals the column index (i === j). For ...

Read More

How to convert a String containing Scientific Notation to correct JavaScript number format?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 2K+ Views

In JavaScript, scientific notation strings like "7.53245683E7" can be converted to regular numbers using several methods. The most straightforward approach is using the Number() function. Using Number() Function The Number() function converts scientific notation strings to decimal numbers: document.write("String with Scientific Notation converted below:"); document.write(Number("7.53245683E7")); String with Scientific Notation converted ...

Read More
Showing 16921–16930 of 61,297 articles
Advertisements