How to convert an array of ints to an array of strings in Node.js

1 Answer

0 votes
function convertToStringArray(numbers) {
    // Map each integer to a string
    return numbers.map(num => num.toString());
}

const numbers = [1, 2, 3, 4, 5, 6];

// Convert the array of integers to a string array
const stringArray = convertToStringArray(numbers);

console.log("String array:");
stringArray.forEach(str => console.log(str));


   
/*
run:
    
String array:
1
2
3
4
5
6
       
*/

 



answered Apr 2 by avibootz
...