Assuming you have an array in a string format, you can use the following regex to match all the decimals and then use .map(Number)

const str = "['6.35', '2.72', '11.79', '183.25']",
      array = str.match(/\d+(?:\.\d+)?/g).map(Number)

console.log(array)

Answer from adiga on Stack Overflow
🌐
Code Highlights
code-hl.com › home › javascript › tutorials
5 Easy Ways to Convert JavaScript Float to Int | Code Highlights
June 4, 2024 - The bitwise OR operator can also convert a float to an integer by truncating the decimal part. ... All these methods are compatible with major web browsers, including Chrome, Firefox, Safari, Edge, and Internet Explorer. This ensures that your code will run smoothly across different environments. In this tutorial, we explored five simple methods to convert a JavaScript float to an int:
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseFloat
parseFloat() - JavaScript | MDN
It stops at the n character, and treats the preceding string as a normal integer, with possible loss of precision. If a BigInt value is passed to parseFloat(), it will be converted to a string, and the string will be parsed as a floating-point number, which may result in loss of precision as well.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript float to int
How to Convert a Float Number to Int in JavaScript | Delft Stack
February 2, 2024 - We can apply the bitwise right shift operator (represented by >> characters). It will convert the float value to an integer. Underneath at the binary level, the bitwise right SHIFT operator shifts the binary bits of the operand to the right ...
🌐
Rip Tutorial
riptutorial.com › float to integer
JavaScript Tutorial => Float to Integer
To convert a float to an integer, JavaScript provides multiple methods.
🌐
W3Schools
w3schools.com › js › js_number_methods.asp
JavaScript Number Methods
Safe integers are all integers from -(253 - 1) to +(253 - 1). This is safe: 9007199254740991. This is not safe: 9007199254740992. For a complete reference to all JavaScript properties and methods, with full descriptions and many examples, go to:
🌐
Just Academy
justacademy.co › blog-detail › how-to-convert-float-to-int-in-javascript
How To Convert Float To Int In JavaScript
6) Type Conversion: You can simply convert a float to an integer by assigning it to a variable of type int. JavaScript will automatically truncate the decimal value.
Top answer
1 of 16
2261
var intvalue = Math.floor( floatvalue );
var intvalue = Math.ceil( floatvalue ); 
var intvalue = Math.round( floatvalue );

// `Math.trunc` was added in ECMAScript 6
var intvalue = Math.trunc( floatvalue );

Math object reference


Examples

Positive
// value=x        //  x=5          5<x<5.5      5.5<=x<6  

Math.floor(value) //  5            5            5
Math.ceil(value)  //  5            6            6
Math.round(value) //  5            5            6
Math.trunc(value) //  5            5            5
parseInt(value)   //  5            5            5
~~value           //  5            5            5
value | 0         //  5            5            5
value >> 0        //  5            5            5
value >>> 0       //  5            5            5
value - value % 1 //  5            5            5
Negative
// value=x        // x=-5         -5>x>=-5.5   -5.5>x>-6

Math.floor(value) // -5           -6           -6
Math.ceil(value)  // -5           -5           -5
Math.round(value) // -5           -5           -6
Math.trunc(value) // -5           -5           -5
parseInt(value)   // -5           -5           -5
value | 0         // -5           -5           -5
~~value           // -5           -5           -5
value >> 0        // -5           -5           -5
value >>> 0       // 4294967291   4294967291   4294967291
value - value % 1 // -5           -5           -5
Positive - Larger numbers
// x = Number.MAX_SAFE_INTEGER/10 // =900719925474099.1

// value=x            x=900719925474099    x=900719925474099.4  x=900719925474099.5
           
Math.floor(value) //  900719925474099      900719925474099      900719925474099
Math.ceil(value)  //  900719925474099      900719925474100      900719925474100
Math.round(value) //  900719925474099      900719925474099      900719925474100
Math.trunc(value) //  900719925474099      900719925474099      900719925474099
parseInt(value)   //  900719925474099      900719925474099      900719925474099
value | 0         //  858993459            858993459            858993459
~~value           //  858993459            858993459            858993459
value >> 0        //  858993459            858993459            858993459
value >>> 0       //  858993459            858993459            858993459
value - value % 1 //  900719925474099      900719925474099      900719925474099
Negative - Larger numbers
// x = Number.MAX_SAFE_INTEGER/10 * -1 // -900719925474099.1

// value = x      // x=-900719925474099   x=-900719925474099.5 x=-900719925474099.6

Math.floor(value) // -900719925474099     -900719925474100     -900719925474100
Math.ceil(value)  // -900719925474099     -900719925474099     -900719925474099
Math.round(value) // -900719925474099     -900719925474099     -900719925474100
Math.trunc(value) // -900719925474099     -900719925474099     -900719925474099
parseInt(value)   // -900719925474099     -900719925474099     -900719925474099
value | 0         // -858993459           -858993459           -858993459
~~value           // -858993459           -858993459           -858993459
value >> 0        // -858993459           -858993459           -858993459
value >>> 0       //  3435973837           3435973837           3435973837
value - value % 1 // -900719925474099     -900719925474099     -900719925474099
2 of 16
348

Bitwise OR operator

A bitwise or operator can be used to truncate floating point figures and it works for positives as well as negatives:

function float2int (value) {
    return value | 0;
}

Results

float2int(3.1) == 3
float2int(-3.1) == -3
float2int(3.9) == 3
float2int(-3.9) == -3

Performance comparison?

I've created a JSPerf test that compares performance between:

  • Math.floor(val)
  • val | 0 bitwise OR
  • ~~val bitwise NOT
  • parseInt(val)

that only works with positive numbers. In this case you're safe to use bitwise operations well as Math.floor function.

But if you need your code to work with positives as well as negatives, then a bitwise operation is the fastest (OR being the preferred one). This other JSPerf test compares the same where it's pretty obvious that because of the additional sign checking Math is now the slowest of the four.

Note

As stated in comments, BITWISE operators operate on signed 32bit integers, therefore large numbers will be converted, example:

1234567890  | 0 => 1234567890
12345678901 | 0 => -539222987
Find elsewhere
🌐
Itsourcecode
itsourcecode.com › home › converting floats to integers in javascript: 10 effective ways
Converting Floats to Integers in JavaScript: 10 Effective Ways
July 27, 2023 - Find out the different methods to achieve JavaScript float to int conversion effectively. Do you want to know how to convert float numbers...
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-convert-a-float-number-to-the-whole-number-in-javascript
How to Convert a Float Number to the Whole Number in JavaScript? | GeeksforGeeks
September 16, 2024 - Below are various methods to convert float numbers to whole numbers in JavaScript: ... Round off the number passed as a parameter to its nearest integer in the Downward direction.
🌐
W3Schools
w3schools.com › js › js_numbers.asp
JavaScript Numbers
Javascript numbers are always double (64-bit floating point). Integers (numbers without a period or exponent notation) are accurate up to 15 digits.
🌐
Byby
byby.dev › js-float-to-int
How to convert float to integer in JavaScript
You can use various methods that either round, truncate, or parse the float value. Depending on your specific use case, you can choose the most appropriate method: Using Math.trunc(). This method returns the integer part of a number by removing any fractional digits.
🌐
TutorialsPoint
tutorialspoint.com › How-do-I-convert-a-float-number-to-a-whole-number-in-JavaScript
How do I convert a float number to a whole number in JavaScript?
In the above output users can see that Math.trunc() method has removed the decimal part and Math.round() method has rounded the number to nearest integer. In this approach, we will use the parseInt() method. The parseInt() method extracts the whole number from the float number or string in ...
🌐
W3Schools
w3schools.com › jsref › jsref_parsefloat.asp
JavaScript parseFloat() Method
at() charAt() charCodeAt() codePointAt() concat() constructor endsWith() fromCharCode() includes() indexOf() isWellFormed() lastIndexOf() length localeCompare() match() matchAll() padEnd() padStart() prototype repeat() replace() replaceAll() search() slice() split() startsWith() substr() substring() toLocaleLowerCase() toLocaleUpperCase() toLowerCase() toString() toUpperCase() toWellFormed() trim() trimEnd() trimStart() valueOf() JS Typed Arrays · Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array BigInt64Array BigUint64Array Float16Array Float32Array Float64Array JS Typed Reference
🌐
Reddit
reddit.com › r/javascript › [askjs] its about time javascript should get a "integer" and "float" data type.
r/javascript on Reddit: [AskJS] Its about time javascript should get a "integer" and "float" data type.
August 10, 2022 -

After all the improvements/features and fixes which were made to javascript (or precisely ECMAScript) since ES6 (ES2015) till now (ES2022), isn't it about time to fix the ultimate pending weakness i.e. having an Integer and a Float type as well (just like "var" keyword was/is there but they added "let" and "const" as a better semantics and good practice) and not just mashup everything in Number.

Heck, we even got a big int to represent big integers (no floats allowed) but we still don't have Integer's and Floats which are SUPER useful in almost every scenario.

So, why is it still not added and not planned as well? Those are VERY important data types and MOST languages HAVE those data types as they are NEEDED, why is it not planned for ECMAScript? Is it planned? Do you want to see this added?

🌐
Reddit
reddit.com › r/programmeranimemes › hey javascript, can you turn my float into int properly?
[Mature Content] r/ProgrammerAnimemes on Reddit: Hey JavaScript, can you turn my float into int properly?
February 3, 2022 - I haven’t actually tried that (I’m on my phone) but casting to a number and then making that an integer seems the most straightforward. Plus it’s not limited to 31 bits (try 3_000_000_000 in yours) ... Javascript dont has int or float type, all they has is number type and bignumber, so ...