Était-ce utile?


How to convert array of decimal strings to array of integer strings without decimal in JavaScript

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

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"];


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;


The output in the console −

[ 1, -2, 5, 8 ]
Published on 10-Oct-2020 11:21:34
Était-ce utile?
Non affilié à Tutorialspoint
scroll top