Javascript Articles

Page 390 of 534

Swap certain element from end and start of array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 252 Views

We need to write a JavaScript function that accepts an array of numbers and a position k, then swaps the kth element from the beginning with the kth element from the end of the array. Understanding the Problem For an array with indices 0 to n-1, the kth element from start is at index k-1, and the kth element from end is at index n-k. We swap these two elements. Example Implementation const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const swapNth = (arr, k) => { ...

Read More

Set the opacity of an image with CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 226 Views

To set the opacity of an image, you can use the CSS opacity property. This is the modern standard method that works across all browsers. The opacity property accepts values from 0 (completely transparent) to 1 (completely opaque). Syntax opacity: value; Where value is a number between 0 and 1: 0 = completely transparent (invisible) 0.5 = 50% transparent 1 = completely opaque (default) Example: Basic Image Opacity .opacity-demo { ...

Read More

Shift certain array elements to front of array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 269 Views

We are required to write a JavaScript function that takes in an array of numbers. The function should bring all the 3-digit integers to the front of the array. Let's say the following is our array of numbers: const numList = [1, 324, 34, 3434, 304, 2929, 23, 444]; Understanding 3-Digit Numbers A 3-digit number is any integer between 100 and 999 (inclusive). We can check this using a simple condition: const isThreeDigit = num => num > 99 && num < 1000; console.log(isThreeDigit(324)); // true console.log(isThreeDigit(34)); // ...

Read More

Usage of -moz-opacity property with CSS

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 856 Views

The -moz-opacity property was a Mozilla-specific CSS property used to set the opacity of HTML elements, including images. This property created transparent effects in older Firefox browsers before the standard opacity property was widely supported. Browser-Specific Opacity Properties Different browsers historically required different approaches for opacity: Mozilla Firefox: -moz-opacity Internet Explorer: filter: alpha(opacity=x) Modern browsers: opacity (standard) Syntax /* Legacy Mozilla syntax */ -moz-opacity: value; /* IE filter syntax */ filter: alpha(opacity=value); /* Modern standard syntax */ opacity: value; The value ranges from 0 (completely transparent) to 1 ...

Read More

Square every digit of a number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 486 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated. For example: If the number is − 9119 Then the output should be − 811181 because 9² is 81 and 1² is 1. Example Following is the code − const num = 9119; const squared = num => { const numStr = String(num); let res = ''; ...

Read More

CSS padding-right property

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 250 Views

The padding-right property in CSS specifies the amount of space between the content and the right border of an element. It adds internal spacing on the right side without affecting the element's border or margin. Syntax padding-right: value; The value can be specified in: Length units: px, em, rem, pt, etc. Percentage: % (relative to parent element's width) Keywords: inherit, initial, unset Example: Length Values .box { ...

Read More

Sorting Array with JavaScript reduce function - JavaScript

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

We are required to write a JavaScript function that takes in an array of numbers. The function should sort the array without using the Array.prototype.sort() method. We are required to use the Array.prototype.reduce() method to sort the array. Let's say the following is our array: const arr = [4, 56, 5, 3, 34, 37, 89, 57, 98]; Understanding the Approach The reduce() method can be used to build a sorted array by iterating through each element and placing it in the correct position within an accumulator array. We'll use insertion sort logic within the ...

Read More

CSS padding property

Samual Sam
Samual Sam
Updated on 15-Mar-2026 219 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

Trying to get number for each character in string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

We are required to write a JavaScript function that takes in a string. It should print out each number for every corresponding letter in the string. For example, a = 1 b = 2 c = 3 d = 4 e = 5 . . . Y = 25 Z = 26 Therefore, if the input is "hello man", Then the output should be a number for each character − "8, 5, 12, 12, 15, 13, 1, 14" How It Works The solution uses the charCodeAt() method to get ...

Read More

Usage of CSS border-collapse property

Chandu yadav
Chandu yadav
Updated on 15-Mar-2026 75 Views

The border-collapse CSS property controls how adjacent table cell borders are displayed. It determines whether borders should merge together or remain separate. Syntax border-collapse: collapse | separate | initial | inherit; Values Value Description collapse Adjacent borders are merged into a single border separate Each cell maintains its own borders (default) initial Sets to default value (separate) inherit Inherits from parent element Example Here's a comparison showing both collapse and separate values: ...

Read More
Showing 3891–3900 of 5,340 articles
« Prev 1 388 389 390 391 392 534 Next »
Advertisements