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; }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo