'1,2,3,4,5'.split(','); The above code will output ['1','2','3','4','5'] ; Each value in the array is of string type. Is there any good way to make the values in the split array become number type?
The type of your split ('1,2,3,4,5') is originally a string, just a string composed of numbers. Therefore, it is right for the array formed after split to maintain its original type. Because it is not a numeric type. To change it to number type, just iterate through the array and convert each element.
You can only traverse it again after splitting
const a ='123456';
a.split(' ').map (i => Number(i))
The type of your split ('1,2,3,4,5') is originally a string, just a string composed of numbers. Therefore, it is right for the array formed after split to maintain its original type. Because it is not a numeric type. To change it to number type, just iterate through the array and convert each element.