javascript - I am taking user input and splitting it - how to best check types for each and also remove spaces? -
i'm not sure if there's better way this.
basically, taking user inputs example - hair salon, 1, 4
when split ,
['hair salon',' 1',' 4']
. doing error check make sure 3 values passed max, how can remove spaces (' 4'
) , check 'hair salon'
string, , other 2 numbers?
thanks
suppose have user input
hair salon, 1, 4
now split(','), array
var arr = ['hair salon', '1','4']
you every input string
for(i=0;i<arr.length;i++) { arr[i] = arr[i].trim() // remove space & front }
in case needed data type of inputs, can check using
typeof (arr[i])) - in loop
hope, suffice need
Comments
Post a Comment