How to split() a string to an array of integers
问题 I have a string that should be executed as an array: var q = "The, 1, 2, Fox, Jumped, 3, Over, 4"; var z = q.split(','); If I use split() , it will create an array of strings: [‘The’, '1', '2', ‘Fox’, ‘Jumped’, '3', ‘Over’, '4'] and I don’t need that. I need an array like: [‘The’, 1, 2, ‘Fox’, ‘Jumped’, 3, ‘Over’, 4] indicating which is a string and which is a number. 回答1: One option is using the Number constructor which returns a number or NaN : var res = q.split(',').map(el => { let n =