
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to convert array of decimal strings to array of integer strings without decimal in JavaScript
We are required to write a JavaScript function that takes in an array of decimal strings. The function should return an array of strings of integers obtained by flooring the original corresponding decimal values of the array.
For example, If the input array is −
const input = ["1.00","-2.5","5.33333","8.984563"];
Then the output should be −
const output = ["1","-2","5","8"];
Example
The code for this will be −
const input = ["1.00","-2.5","5.33333","8.984563"]; const roundIntegers = arr => { const res = []; arr.forEach((el, ind) => { const strNum = String(el); res[ind] = parseInt(strNum); }); return res; }; console.log(roundIntegers(input));
Output
The output in the console −
[ 1, -2, 5, 8 ]
- Related Articles
- How to convert array of strings to array of numbers in JavaScript?
- How to convert array of comma separated strings to array of objects?
- Python - Ways to convert array of strings to array of floats
- Sorting strings with decimal points in JavaScript
- How to create an array of strings in JavaScript?
- Binary array to corresponding decimal in JavaScript
- Convert decimal integer to octal in Java
- Convert integer array to string array in JavaScript?
- How to create array of strings in Java?
- Convert an array of datetimes into an array of strings in Python
- Convert decimal integer to hexadecimal number in Java
- How to convert Decimal to Binary in JavaScript?
- How to convert Binary to Decimal in JavaScript?
- How can I convert an array to an object by splitting strings? JavaScript
- How to convert Integer array list to integer array in Java?

Advertisements