How to get a number value of a string in Javascript?

Nancy Den
Updated on 15-Mar-2026 23:18:59

612 Views

To extract numeric values from strings in JavaScript, you have several approaches depending on your needs. The most common methods are using regular expressions with parseInt(), parseFloat(), or Number(). Using parseInt() with Regular Expression For extracting integers from strings containing mixed content, combine parseInt() with match() and a regex pattern: var myStr = "abcdef 30"; var num = parseInt(myStr.match(/\d+/)); console.log("Extracted number:", num); ... Read More

How to set the painting area of the background with JavaScript?

Shubham Vora
Updated on 15-Mar-2026 23:18:59

389 Views

In this tutorial, we will learn how to set the painting area of the background with JavaScript using the backgroundClip property. The background-clip CSS property defines how far a background (color or image) extends within an element. It specifies whether the background extends beneath the border-box, padding-box, or content-box of an element. Understanding background-clip Property The background-clip property accepts three main values: border-box - Background extends to the outer edge of the border (default) padding-box - Background extends to the outer edge of the padding content-box ... Read More

How to set focus on a text input in a list with AngularJS and HTML5

karthikeya Boyini
Updated on 15-Mar-2026 23:18:59

562 Views

To set focus on a text input in a list with AngularJS, you need to create a custom directive that observes a focus attribute and programmatically sets focus when the condition is met. Creating the Focus Directive First, create a custom directive that will handle the focus functionality: Focus state: {{cue.isNewest}} ... Read More

Font size adjust of an element with CSS

Giri Raju
Updated on 15-Mar-2026 23:18:59

285 Views

The font-size-adjust CSS property enables you to adjust the x-height to make fonts more legible when fallback fonts are used. It helps maintain consistent visual font sizes across different font families. Syntax font-size-adjust: none | number; Parameters none - Default value. No font size adjustment. number - A positive number that specifies the aspect ratio (x-height divided by font size). How It Works The property calculates: adjusted font size = specified font size × (font-size-adjust value ÷ aspect ratio of actual font) ... Read More

Add sizes for Bootstrap Buttons

Arjun Thakur
Updated on 15-Mar-2026 23:18:59

342 Views

Bootstrap provides several CSS classes to control button sizes, from large buttons to block-level buttons that span the full width of their container. Button Size Classes Class Description .btn-lg ... Read More

No. of ways to empty an array in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

272 Views

JavaScript provides several methods to empty an array. Each method has different use cases and behaviors, especially when multiple references to the same array exist. Method 1: Setting to New Array This method creates a new empty array and assigns it to the variable. However, it doesn't affect other references to the original array. Setting to New Array let arr = [1, 2, 3, ... Read More

Solution to the clumsy factorial problem in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

440 Views

Normally, the factorial of a positive integer n is the product of all positive integers less than or equal to n. For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. We instead make a clumsy factorial: using the integers in decreasing order, we swap out the multiply operations for a fixed rotation of operations: multiply (*), divide (/), add (+) and subtract (-) in this order. For example, clumsy(10) = 10 * 9 / 8 + 7 - 6 * 5 / 4 + ... Read More

Add two array keeping duplicates only once - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

169 Views

When working with two arrays, you often need to merge them while keeping only unique values. This operation combines arrays and removes duplicates in a single step. const arr1 = [2, 4, 5, 3, 7, 8, 9]; const arr2 = [1, 4, 5, 2, 3, 7, 6]; We need to write a JavaScript function that takes two arrays and returns a new array with all duplicates removed (each element appears only once). Using Set with Spread Operator (Recommended) The most efficient approach uses ES6 Set to automatically remove duplicates: const arr1 = ... Read More

Converting array to object by splitting the properties - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

327 Views

We have an array of string literals in which each element has a dash (-). The property key is present to the left of dash and its value to the right. A sample input array would look something like this: const arr = ["playerName-Kai Havertz", "age-21", "nationality-German", "position-CAM", "languages-German, English, Spanish", "club-Chelsea"]; We are required to write a function that splits these strings and form an object out of this array. Let's write the code. It will loop over the array splitting each string and feeding it into the new object. Using forEach Method ... Read More

How to return a value from a JavaScript function?

Srinivas Gorla
Updated on 15-Mar-2026 23:18:59

3K+ Views

To return a value from a JavaScript function, use the return statement. The return statement sends a value back to the code that called the function and immediately exits the function. Syntax function functionName() { // function body return value; } Example: Basic Return Statement function concatenate(name, age) { var val = name + age; ... Read More

Advertisements