How to convert an array of integers to a string in JavaScript

1 Answer

0 votes
function convertArrayOfIntegersToString(arr) {
    let result = [];
    
    for (let i = 0; i < arr.length; i++) {
        result.push(arr[i]);
        result.push(" ");
    }
    
    return result.join('').trim();
}

const arr = [5, 8, 12, 800, 3907];

const s = convertArrayOfIntegersToString(arr);

console.log(s);



/*
run:

5 8 12 800 3907

*/

 



answered Jul 31, 2024 by avibootz
edited Jul 31, 2024 by avibootz
...