What are the common methods used by Javasrcipt?

Source: Internet
Author: User
Tags what array

What are the common methods of Javasrcipt string objects?

1, Stringobject.indexof (searchvalue,fromindex) returns the position of the first occurrence of a specified string value in a string. The function is case-sensitive and returns 1 if the found character does not exist.

2, Stringobject.match (Searchvalue)

2, Stringobject.match (regexp)

2. Difference between match and test

The match () method is also case sensitive and returns a matching value.

Test is a regexp method, the argument is a string, and the return value is a Boolean type.

Match is a method of string, the parameter is a regular expression, and the return value is an array.

3, Stringobject.replace (regexp/substr,replacement) substitutes some characters in the string, or replaces a substring that matches a regular expression.

var str= "Visit microsoft!"

Str.replace (/microsoft/, "W3school")

put Microsoft Switch to W3school

var str= "Welcome to microsoft! "

Str=str + "We are proud to announce that Microsoft have"

Str=str + "One of the largest WEB developers sites in the world."

Str.replace (/microsoft/g, "W3school")

global substitution, put Microsoft Switch to W3school

include property "G", "I", and "M", respectively, for specifying global matching, case-sensitive matching, and multi-line matching.

4, Stringobject.slice (start,end) extracts a portion of a string and returns the extracted part with a new string. A new string. Includes the string Stringobject all characters from start (including start) to end (not including end).

5, Stringobject.split (separator,howmany) string Segmentation array

<script type= "Text/javascript" >

var str= "How is you doing today?"

document.write (Str.split ("") + "<br/>") are divided into words,

How,are,you,doing,today?

document.write (Str.split ("") + "<br/>") split into letters

H,o,w,, A,r,e,, Y,o,u,, D,o,i,n,g,, T,o,d,a,y,?

document.write (Str.split ("", 3))

How,are,you

</script>

The action performed by String.Split () is the opposite of what Array.join does.

6, Stringobject.substr (start,length) Extract string part

What are the common methods for Javasrcipt array objects?

1, Arrayobject.join (separator) puts all the elements in the array into a string.

2, Arrayobject.pop () deletes and returns the last element of the array.

3, Arrayobject.push (Newelement1,newelement2,...., newelementx)

Adds one or more elements to the end of the array and returns the new length.

4, Arrayobject.unshift (Newelement1,newelement2,...., newelementx)

Adds one or more elements to the beginning of the array and returns the new length.

5, Arrayobject.reverse () reverses the order of the elements in the array.

6, Arrayobject.shift () deletes and returns the value of the first element of the array.

What are the common methods of Javasrcipt date objects?

Http://www.w3school.com.cn/jsref/jsref_obj_date.asp

Iv. What are the common methods of the math objects of Javasrcipt?

Math.random () returns a random number between 0-1

Math.ceil () rounding up

Http://www.w3school.com.cn/jsref/jsref_obj_math.asp

What are the common methods used by Javasrcipt?

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.