JS Front End pen question Analysis _javascript skill

Source: Internet
Author: User
Tags getdate

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.

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.