javascript - convert array of numbers in array of strings using map -
im using lodash, , im trying convert array of numbers in strings, convert numbers since in array there null values. tried using map of lodash in map javascript messing null values.
example of array: [1245, 5845, 4585, null, null]
code:
var meds = _.map(lines,'med_id').map(string);
result: ["1245", "5845", "4585", "null", "null"];
should be: ["1245", "5845", "4585", null, null];
you need test type of value before calling string
var meds = _.map(lines, 'med_id').map(function(x) { return typeof x == 'number' ? string(x) : x; });