You're not returning the stringified content so the function transforms the array into undefineds. Array#map transforms each array element based on the return value of the passed callback and since yours returns nothing it transforms them to undefined:
var numbers = [1, 2, 3, 4, 5, 6, 7, 8];
var stringifiedNumbers = numbers.map(function(x) {
return JSON.stringify(x);
})
console.log(stringifiedNumbers);
You could shorten this with arrow functions:
var stringifiedNumbers = numbers.map(x => JSON.stringify(x));
Because you are only using one return statement in the example above, you can implicitly return the expression with an arrow function. You could even just shorten it to:
numbers.map(JSON.stringify);
As it implicitly passes the argument and gets rid of the variable.
JSON.stringifyfor a simple numeric. Just usereturn x.toString()