Javascript Articles

Page 340 of 534

How to find a group of three elements in an array whose sum equals some target sum JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 623 Views

We need to write a function that finds three elements in an array whose sum equals a target value. The function should return the indices of these three elements, or -1 if no such triplet exists. Approach We'll use a two-step approach: Create a twoSum() helper function that finds two numbers adding up to a target sum Iterate through each element and use twoSum() to find the remaining two elements This approach has O(N²) time complexity, where N is the array length. How It Works The twoSum() function uses a hash map ...

Read More

How to use JavaScript Object.defineProperty?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 313 Views

The Object.defineProperty() method allows you to define a new property or modify an existing property on an object with precise control over its behavior. Syntax Object.defineProperty(obj, prop, descriptor) Parameters obj – The object on which to define the property prop – The name of the property to be defined or modified descriptor – An object that describes the property's attributes Property Descriptor Attributes The descriptor object can contain the following attributes: value – The value of ...

Read More

Counting how many times an item appears in a multidimensional array in JavaScript

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

We have a nested array of strings and we have to write a function that accepts the array and a search string and returns the count of the number of times that string appears in the nested array. Therefore, let's write the code for this, we will use recursion here to search inside of the nested array and the code for this will be − Example const arr = [ "apple", ["banana", "strawberry", "dsffsd", "apple"], "banana", ["sdfdsf", "apple", ["apple", ["nonapple", "apple", ["apple"]]]] ...

Read More

How to set the minimum number of lines for an element that must be visible at the top of a page in JavaScript?

George John
George John
Updated on 15-Mar-2026 189 Views

The orphans CSS property sets the minimum number of lines in a block container that must be shown at the top of a page when a page break occurs. In JavaScript, you can control this property through the DOM to manage print layout behavior. Syntax // Get the orphans value var orphansValue = element.style.orphans; // Set the orphans value element.style.orphans = "number|initial|inherit"; Parameters Value Description number Minimum number of lines (default is 2) initial Sets to default value inherit Inherits from parent element ...

Read More

Get minimum number without a Math function JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 308 Views

We need to find the smallest number from a set of numbers without using JavaScript's built-in Math.min() function. This requires implementing our own comparison logic. Approach Using While Loop We'll iterate through all numbers and keep track of the smallest value found so far, updating it whenever we encounter a smaller number. Example const numbers = [12, 5, 7, 43, -32, -323, 5, 6, 7, 767, 23, 7]; const findMin = (...numbers) => { let min = Infinity, len = 0; while(len < numbers.length) { ...

Read More

How to set the alignment between the items inside a flexible container when the items do not use all available space with JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 153 Views

The alignContent property in JavaScript controls how flex lines are distributed within a flex container when there's extra space on the cross axis. This property only works when items wrap to multiple lines. Syntax element.style.alignContent = "value"; Available Values The alignContent property accepts these values: flex-start - Lines packed toward the start flex-end - Lines packed toward the end center - Lines packed toward the center space-between - Lines evenly distributed space-around - Lines with equal space around them stretch - Lines stretch to fill the container (default) Example ...

Read More

Check if some elements of array are equal JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 430 Views

We have an array of numbers that have got some redundant entries, our job is to write a function that takes in the array and groups all the identical entries into one subarray and returns the new array thus formed. For example − //If the input array is: const arr = [1, 3, 3, 1]; //then the output should be: const output = [[1, 1], [3, 3]]; We will use a HashMap to keep a track of the elements already occurred and iterate over the array using a for loop. Using HashMap Approach ...

Read More

How to inject JavaScript in WebBrowser control?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 2K+ Views

To inject JavaScript in WebBrowser control, you need to create a Windows Forms application and use the WebBrowser control's document manipulation capabilities. This allows you to dynamically add JavaScript code to web pages loaded in your application. Prerequisites Create a Windows Forms application in Visual Studio Drag a WebBrowser control to the form Set the Url property of the WebBrowser control Right-click the project, choose Add reference... → COM → Type Libraries Select "Microsoft HTML Object Library" ...

Read More

How to set the order of the flexible item, relative to the rest with JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 15-Mar-2026 175 Views

To set the order of flexible items relative to each other in JavaScript, use the order property. This CSS property controls the visual order of flex items without changing the HTML structure. Syntax element.style.order = "value"; The order property accepts integer values (positive, negative, or zero). Items with lower values appear first, and items with the same order value appear in their original HTML order. Example Here's how to reorder flex items dynamically using JavaScript: ...

Read More

Is their JavaScript scroll event for iPhone/iPad?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 430 Views

Yes, iOS Safari captures scroll events on iPhone and iPad. However, iOS handles scrolling differently than desktop browsers, using momentum scrolling and gesture-based interactions. Basic Scroll Event Detection You can use the standard scroll event listener on iOS devices: Scroll this content on mobile... Content line 2 Content line 3 Content line 4 Content line 5 Scroll position: 0 const scrollable = document.getElementById('scrollable'); const output = ...

Read More
Showing 3391–3400 of 5,340 articles
« Prev 1 338 339 340 341 342 534 Next »
Advertisements