Built-in functions in JavaScript

Source: Internet
Author: User

I. Basic Library of functions

Split (): Used to split a string into a string array

toUpperCase ():

SUBSTR ():

Length

Length ()

splicing (two kinds)

+

Concat (): Merges multiple strings and returns the results of the merge

Find

The IndexOf () method returns the position of the first occurrence of a specified string value in a string

LastIndexOf (): Returns the last occurrence of a specified string value, in a string at the specified position from the back to the forward search

Delete/Add

Shift (): Used to remove the first element of the array and return the value of the first element

Pop (): Used to delete and return the last element of an array

Unshift (): You can add one or more elements to the beginning of the array and return the new length

Push (): You can add one or more elements to the end of the array and return the new length

Intercept

SUBSTR (start,end): Extracts a specified number of characters from the start subscript in a string

Simple example:

<script type= "Text/javascript" >var str= "I like PHP";//split to get each word var arr=str.split ("");//iterate over the array, get the first letter, uppercase, Put back in place var word= ""; var nstr= ""; for (var k in arr) {word=arr[k][0].touppercase () +arr[k].substr (1); nstr+=word+ "";} document.write (NSTR);</script>

To detect what the browser is:

<script type= "Text/javascript" >if (Navigator.userAgent.toLowerCase (). IndexOf ("MSIE") >=0) {document.write ("ie");} else if (Navigator.userAgent.toLowerCase (). IndexOf (' Firefox ') >=0) {document.write ("Huohu");} else if (Navigator.userAgent.toLowerCase (). IndexOf (' Chrome ') >=0) {document.write (' Google ');} </script>

A small example of a timer (review some basic functions):

Date ()

SetInterval ()

Getinterval ()

toLocaleString ()

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

Get URL Address:

Parse the following URL:

Http://www.xxx:8080/test.php?user=admin&pwd=admin#login

      1. Location.href: Get the complete URL as above
      2. Location.protocol: Get the Transport protocol http:
      3. Location.host: Get host name together with Port www.xxx.cn:8080
      4. Location.hostname: Get host name www.xxx.cn
      5. Location.pathname: Get the host after part does not include the question mark? The latter part of the/test.php
      6. Location.search: Get the question mark in the URL, then the part before the pound #? user=admin&pwd=admin
      7. Location.hash: Get the part before # #login
<script type= "Text/javascript" >document.write ("href:" +location.href+ "<br/>");
Set the current host name and port number document.write ("Host:" +location.host+ "<br/>");d ocument.write ("Pathname:" +location.pathname + "<br/>");d ocument.write ("Search:" +location.search+ "<br/>");d ocument.write ("Hash:" +location.hash+ " <br/> location.replace ("http://www.baidu.com");</script>

JS Object-oriented: http://www.dreamdu.com/javascript/define_object/

Built-in functions in JavaScript

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.