javascript - How to split and get selection data from an array -


i have array in javascript

var = [1,2,3,4,5,"4","12","2",6,7,"4",3,"2"];  

my questions are

  1. how split array change, (comma) ";"

  2. how return number of strings in array return total value regardless of variable type.

  3. how return average value (regardless of variable type again)

answering question 1

1.convert string

var x=a.tostring(); 

2.perform global replace

var y= x.replace(/,/g,";"); 

3.this gives "1;2;3;4;5;4;12;2;6;7;4;3;2"

for question 2 use a.length method.this give total number of elements.i'm not sure string elements part.


Comments