This article analyzes the JS front-end pen test. Share to everyone for your reference, specific as follows:
1. How do I create an array based on a comma-delimited string? Please create an array for the following string and access the third element: "Cats,dogs,birds,horses"
Knowledge Points: Conversion of arrays and strings. Review the Split () method. Splits a string into an array of strings (the string is cut into several strings by one character and returned as an array)
var animalstring= "cats,dogs,birds,horses";
var animalarray=animalstring.split (",");
Alert (animalarray[2]);
If you use alert (animalstring[2) directly, the output is T
Extensions: Array-> strings
var animalarray =new Array ("cats,dogs,birds,horses");
var animalstring=animalarray.join ("-");
Alert (animalstring[2]);
Note: The first line can be abbreviated VAR animalarray =["Cats,dogs,birds,horses"];
The output is T.
2. Write a program code that gets today's date and calculates the date of the same day of the next week.
var d=new Date ();
var today=d.getfullyear () + "-" + (D.getmonth () +1) + "-" +d.getdate ();
alert (today);
D.settime (D.gettime () +7*24*3600*1000);
var nexttoday=d.getfullyear () + "-" + (D.getmonth () +1) + "-" +d.getdate ();
alert (nexttoday);
For more on JavaScript related content to view the site topics: "JavaScript object-oriented Tutorial", "javascript json operation tips Summary", "JavaScript switching effects and techniques summary", " JavaScript Search Algorithm Skills summary, javascript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical Operational Usage Summary
I hope this article will help you with JavaScript programming.