Overview:
The split () method splits a string into an array of strings and returns this array
Syntax format:
1 |
stringObject.split(separator,limit) |
Parameter description:
Note: If you use an empty string ("") as a separator, then each character in the Stringobject will be split.
Example:
An interesting chestnut:
Requirements Description:
Student performance data are as follows:
"Xiao Ming: 87; Floret: 81; Little Red: 97; Small day: 76; Xiao Zhang: 74; little: 94; Xiao XI: 90; Xiao Wu: 76; Dicky: 64; Small ord: 76 "
Output requirements:
1. Display the date of printing. The format is similar to the current time of "xxxx year XX month XX day week X".
2, calculate the average of the Class (Reserved integer)
Demo Address: Http://codepen.io/anon/pen/yNMmxE
Get the current date by using the JavaScript Date object and output. var idate= new Date (); var iyear=idate.getfullyear (); var imonth=idate.getmonth () +1; var iday=idate.getdate (); var weeks=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var iweek =weeks[idate.getday ()]; var itime=iyear+ "Year" +imonth+ "month" +iday+ "Day" +iweek; The result is a long-channeling string bad processing, find the rule after the division put into the array better operation Oh var scorestr = "Xiao Ming: 87; Floret: 81; Little red: 97; Small day: 76; Xiao Zhang: 74; little: 94; Xiao XI: 90; Xiao Wu: 76; Dicky: 64; Small Ord: 76 "; var scores=scorestr.split (";"); var arrlength=scores.length; var sum=0; var average=null; for (Var i=0;i<arrlength;i++) { sum+=parseint (Scores[i].split (":") [1]) }average=sum/arrlength; document.write (itime+ "--" +average);
Javascript: String Split split () magical