How to convert an array of integers to a string in Node.js

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 = [3, 4, 60, 767, 7891];

const s = convertArrayOfIntegersToString(arr);

console.log(s);



/*
run:

3 4 60 767 7891

*/

 



answered Jul 31, 2024 by avibootz

Related questions

...