JS front-end question analysis and JS Question Analysis
This article analyzes the JS front-end pen questions. We will share this with you for your reference. The details are as follows:
1. How to create an array based on a comma-separated string? Create an array for the following strings and access the third element: "cats, dogs, birds, horses"
Knowledge Point: array and String Conversion. Evaluate the knowledge of the split () method. Splits a string into a String Array (splits the string into several strings based on a specific character and returns the string as an array)
Var animalString = "cats, dogs, birds, horses"; var animalArray = animalString. split (","); alert (animalArray [2]);
If alert (animalString [2]) is used directly, t is output.
Extended: array-> string
Var animalArray = new Array ("cats, dogs, birds, horses"); var animalString = animalArray. join ("-"); alert (animalString [2]);
Note: The first line can be abbreviated as var animalArray = ["cats, dogs, birds, horses"];
The output is t.
2. Write a program code to get the date of today and calculate 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 );