Javascript Articles

Page 386 of 534

Merging boolean array with AND operator - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 824 Views

Let's say, we have an array of arrays of boolean like this − const arr = [[true, false, false], [false, false, false], [false, false, true]]; We are required to write a function that merges this array of arrays into a one-dimensional array by combining the corresponding elements of each subarray using the AND (&&) operator. Let's write the code for this function. We will be using Array.prototype.reduce() function to achieve this. Example Following is the code − const arr = [[true, false, false], [false, false, false], [false, false, true]]; const ...

Read More

What are the ways to include style sheet rules in an HTML document

seetha
seetha
Updated on 15-Mar-2026 618 Views

There are three main ways to include CSS styles in an HTML document: inline styles using the style attribute, internal stylesheets using the element, and external stylesheets using the element. Method 1: Inline Styles Inline styles are applied directly to HTML elements using the style attribute: Inline Styles Example Inline Styled Heading This paragraph has inline styles. Method 2: Internal Stylesheets Internal stylesheets are defined within the element in the document's ...

Read More

Prime numbers upto n - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 694 Views

Let's say, we are required to write a JavaScript function that takes in a number, say n, and returns an array containing all the prime numbers up to n. For example − If the number n is 24, then the output should be − const output = [2, 3, 5, 7, 11, 13, 17, 19, 23]; Method 1: Basic Prime Check Approach This approach uses a helper function to check if each number is prime: const num = 24; const isPrime = num => { let count ...

Read More

What is pica? How to set the font size in CSS using pica?

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

A pica is a CSS unit of measurement primarily used in print design. One pica equals 12 points, and there are 6 picas per inch (1pc = 12pt = 1/6 inch). The pica unit is specified using "pc" in CSS. Understanding Pica Units Picas are absolute units like pixels, but they're based on traditional typography measurements: 1 pica = 12 points 6 picas = 1 inch 1pc ≈ 16 pixels (at 96 DPI) Syntax font-size: value pc; /* Examples */ font-size: 1pc; /* 12 points */ font-size: 2.5pc; ...

Read More

Replacing all special characters with their ASCII value in a string - JavaScript

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

We are required to write a JavaScript function that takes in a string that might contain some special characters. The function should return a new string with all special characters replaced with their corresponding ASCII value. Understanding Special Characters Special characters are symbols that are not letters, numbers, or spaces. Examples include !, @, #, $, etc. Each character has a unique ASCII code that can be retrieved using the charCodeAt() method. Example Following is the code: const str = 'Th!s !s @ str!ng th@t cont@!ns some special characters!!'; const specialToASCII = str ...

Read More

Which property is used in CSS to control the repetition of an image in the background?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

To control the repetition of an image in the background, use the background-repeat property. You can use no-repeat value for the background-repeat property if you do not want to repeat an image, in this case, the image will display only once. Syntax background-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round; Common Values Value Description repeat Repeats both horizontally and vertically (default) repeat-x Repeats horizontally only repeat-y Repeats vertically only no-repeat Displays image only once Example: Basic Background ...

Read More

Inserting element at falsy index in an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 246 Views

We are required to write an Array function, let's say, pushAtFalsy() The function should take in an array and an element. It should insert the element at the first falsy index it finds in the array. If there are no empty spaces, the element should be inserted at the last of the array. We will first search for the index of empty position and then replace the value there with the value we are provided with. Understanding Falsy Values In JavaScript, falsy values include: null, undefined, false, 0, "" (empty string), and NaN. However, since 0 ...

Read More

Usage of background-color property in CSS

Sravani S
Sravani S
Updated on 15-Mar-2026 141 Views

The background-color property is used to set the background color of an element. It accepts color values in various formats including color names, hexadecimal, RGB, and HSL values. Syntax background-color: color | transparent | inherit | initial; Example: Using Color Names You can use predefined color names to set the background color: Background Color Example This text ...

Read More

Array of adjacent element's average - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 319 Views

Let's say, we have an array of numbers: const arr = [3, 5, 7, 8, 3, 5, 7, 4, 2, 8, 4, 2, 1]; We are required to write a function that returns an array with the average of the corresponding element and its predecessor. For the first element, as there are no predecessors, so that very element should be returned. Let's write the code for this function, we will use the Array.prototype.map() function to solve this problem: Example const arr = [3, 5, 7, 8, 3, 5, 7, 4, 2, 8, ...

Read More

Set the Background Attachment with CSS

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 126 Views

The background-attachment property controls whether a background image scrolls with the content or remains fixed in the viewport. This CSS property is useful for creating parallax effects or keeping decorative backgrounds stationary. Syntax background-attachment: value; Property Values Value Description scroll Background scrolls with content (default) fixed Background stays fixed in viewport local Background scrolls with element's content Example: Fixed Background This example demonstrates a fixed background that remains stationary while content scrolls: ...

Read More
Showing 3851–3860 of 5,340 articles
« Prev 1 384 385 386 387 388 534 Next »
Advertisements