Javascript: String Split split () magical

Source: Internet
Author: User
Tags idate ming ord

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.