Javascript Articles

Page 334 of 534

How to set the style of the left border with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 377 Views

In this tutorial, we shall learn how to set the style of the left border with JavaScript. To set the style of the left border in JavaScript, use the borderLeftStyle property. Set the style under this property that you want for the border i.e. solid, dashed, etc. Using the borderLeftStyle Property With this property, we can set or return the style of the left border of an element. Syntax object.style.borderLeftStyle = style; This syntax allows the required border style to be set to the element's style. Parameters ...

Read More

How to set outline color with JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 579 Views

To set outline color in JavaScript, use the outlineColor property. The outline appears outside an element's border and doesn't affect the element's dimensions or layout. Syntax element.style.outlineColor = "color"; Parameters The outlineColor property accepts any valid CSS color value: Color names: "red", "blue", "green" Hex values: "#FF5733", "#000000" RGB values: "rgb(255, 87, 51)" HSL values: "hsl(9, 100%, 60%)" Example: Setting Outline Color #box { ...

Read More

Sum of consecutive numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 569 Views

Let's say, we have to write a function that takes in an array and returns another array in which the consecutive similar numbers are added up together. For example − const array = [1, 5, 5, 5, 8, 8, 9, 1, 4, 4, 2]; console.log("Original array:", array); Original array: [ 1, 5, 5, 5, 8, 8, 9, 1, 4, 4, 2 ] The output should be − [1, 15, 16, 9, 1, 8, 2] All consecutive 5s added up to 15, then 2 consecutive 8s added up to ...

Read More

How to create a JavaScript code for multiple keys pressed at once?

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

Use the keydown and keyup events in JavaScript to detect multiple keys pressed simultaneously. This technique tracks which keys are currently held down and updates the display accordingly. Example: Multiple Key Detection Multiple Keys Detection .key-up { color: red; } .key-down { color: green; } ul { list-style-type: none; } ...

Read More

Get the longest and shortest string in an array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 789 Views

We have an array of string literals like this: const arr = ['Some', 'random', 'words', 'that', 'actually', 'form', 'a', 'sentence.']; We need to write a function that returns the longest and shortest word from this array. We will use the Array.prototype.reduce() method to keep track of the longest and shortest word during iteration. Using Array.reduce() Method The reduce() method processes each element and maintains an accumulator object containing both the longest and shortest strings found so far: const arr = ['Some', 'random', 'words', 'that', 'actually', 'form', 'a', 'sentence.']; const findWords = ...

Read More

How to set all outline properties in a single declaration with JavaScript?

Paul Richard
Paul Richard
Updated on 15-Mar-2026 189 Views

To set all outline properties in one declaration, use the outline property. It sets the following properties: outline-width, outline-style, and outline-color. Syntax element.style.outline = "width style color"; Parameters The outline property accepts three values in any order: width - thickness (thin, medium, thick, or length value like 2px) style - line style (solid, dashed, dotted, double, groove, ridge, inset, outset) color - outline color (color name, hex, rgb, rgba) Example You can try to run the following code to learn ...

Read More

JavaScript code for recursive Fibonacci series

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 425 Views

We have to write a recursive function fibonacci() that takes in a number n and returns an array with first n elements of fibonacci series. The Fibonacci sequence starts with 0 and 1, where each subsequent number is the sum of the two preceding ones. Understanding the Fibonacci Sequence The Fibonacci sequence follows this pattern: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34... where F(n) = F(n-1) + F(n-2). Recursive Implementation Here's a recursive approach that builds the Fibonacci array: const fibonacci = (n, res = [], count = 1, last = ...

Read More

Create a syntax highlighting code with JavaScript.

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 231 Views

Creating syntax highlighting for code blocks enhances readability and user experience. JavaScript offers several libraries for this purpose, with Google's Prettify being one of the simplest options. Using Google Prettify Library Prettify is a lightweight JavaScript library that automatically highlights code syntax. Include it in your HTML document: Basic Implementation Add the prettyprint class to any or element: function greetUser(name) { return "Hello, " + name + "!"; } ...

Read More

Recursive product of summed digits JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 234 Views

We need to create a function that takes multiple numbers as arguments, adds them together, then repeatedly multiplies the digits of the result until we get a single digit. Problem Breakdown For example, with arguments 16, 34, 42: 16 + 34 + 42 = 92 Then multiply digits until single digit: 9 × 2 = 18 1 × 8 = 8 (final result) Solution Approach We'll break this into two helper functions: produce() - calculates the product of digits in a number using ...

Read More

Is their JavaScript "not in" operator for checking object properties?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 2K+ Views

JavaScript doesn't have a built-in "not in" operator, but you can achieve the same functionality by negating the in operator with ! or using other methods to check if a property doesn't exist in an object. Using Negated "in" Operator The most straightforward approach is to negate the in operator using the logical NOT operator (!): let obj = {name: "John", age: 30}; // Check if property does NOT exist if (!("email" in obj)) { console.log("Email property does not exist"); } else { console.log("Email property exists"); } ...

Read More
Showing 3331–3340 of 5,340 articles
« Prev 1 332 333 334 335 336 534 Next »
Advertisements