Summary of methods for commonly used JS objects

Source: Internet
Author: User
Tags square root

Http://www.cnblogs.com/Yfling/p/6681207.html

String
Method Description
CharAt () Returns the character at the specified position.
charCodeAt () Returns the Unicode encoding of the character at the specified position.
Concat () The connection string.
IndexOf () Retrieves a string.
Match () Finds a match for one or more regular expressions.
Replace () Replace the substring that matches the regular expression.
Search () Retrieves a value that matches a regular expression.
Slice () Extracts a fragment of a string and returns the extracted part in a new string.
Split () Splits a string into an array of strings.
toLocaleLowerCase () Converts the string to lowercase.
toLocaleUpperCase () Converts the string to uppercase.
toLowerCase () Converts the string to lowercase.
toUpperCase () Converts the string to uppercase.
SUBSTR () Extracts a specified number of characters from the starting index number in a string.
SUBSTRING () Extracts the characters between two specified index numbers in a string.
Array
Method Description
Slice[start,end) Returns a new array of entries from the original array that specify the starting subscript to the end of the subscript (without affecting the original array)
. 1 parameters: N. That is: N to the end of all
. 2 parameters: [Start,end]
Splice ():
. Delete: 2 parameters, starting position, number of items deleted
. Insert: 3 parameters, starting position, number of items deleted, inserted item
. Replace: Any parameter, start position, deleted item number, insert any number of items
Pop () Deletes the last element of the array, reduces the length of the array, and returns the deleted value. (no reference)
Push () Loads the parameter to the end of the array, returning the length of the new array. (Unlimited parameters)
Shift () Deletes the first element of the array, minus 1 of the array length, and returns the deleted value. (no reference)
Unshift () Adds one or more elements to the beginning of the array and returns the new length. (Unlimited parameters)
Sort () Sorts the array by the specified parameter, and the returned value is the sorted arrays (no arguments/functions)
Concat (3,4) Stitch together two arrays. The returned value is a copy (unlimited parameters)
Join () Sets the element group of the array as a string, separator as a delimiter, and the default comma delimiter if omitted
IndexOf () Looks backwards from the beginning of the array, accepts two parameters, the item to find (optional), and the index at which to find the start position
LastIndexOf () Start looking forward from the end of the array, accept two parameters, the item to find (optional), and the index at which to find the start position
Every () Runs the given function for each item in the array, and returns True if the function returns true for each item.
Filter () Each item in an array runs the given function, and returns the item that returns true to make up the list.
ForEach () Each item of an array runs the given function, and the method does not return a value.
Map () Each item of an array runs the given function, returning an arrays of the results of each function call.
Some () Runs the given parameter for each item of an array, and returns True if the function returns true for either item. None of the above methods will modify the contained values in the array.
Reduce () and reduceright () The method of narrowing the array, both of which iterate over all the items of the algebraic group, and then build a value that is ultimately returned.

Array Test Cases:

var ages = [32,33,16,40];functionCheckadult(age) {Return Age >=18;}EveryPrint (Ages.every (checkadult))FalsePrint (Ages.some (checkadult))TrueFilterPrint (Ages.filter (checkadult))[32, 33, 40]Foreachvar arr = [1,2,3,4];arr.ForEach (function(ele) {Console.log (Ele)});1 2 3 4var arr = [1,2,3,4];var add =function(ele) {ele++;return ele;}Print (Arr.map (add));return array [2, 3, 4, 5]The reduce () method receives a function as an accumulator (accumulator), and each value (from left to right) in the array begins to shrink, resulting in a value.Example: adding all the items in an arrayvar total = [0,1,2,3].reduce (function(A, b) { return a + b;}, 0);  Print (total) //6 = 0 + 1 + 2 + 3//Reduceright () method takes a function as an accumulator (accumulator) and an array of each value (right-to-left) to reduce it to a single value. //Example let flattened = [[0, 1], [2, 3], [4, 5]].reduceright ((A, b) + = { return a.conc at (b);}, []); print (flattened) [4, 5, 2, 3, 0, 1]        
Math
Method Description
Ceil (x) Take the maximum possible.
Floor (x) Take the minimum possible.
Round (x) Rounds the number to the nearest integer.
Max (x, y) Returns the highest value in X and Y.
Min (x, y) Returns the lowest value in X and Y.
Pow (x, y) Returns the Y power of X.
Random () Returns a random number between 0 and 1.
sqrt (x) Returns the square root of the number.
Regular
Method Description
Compile Compiles the regular expression.
Exec Retrieves the value specified in the string. Returns the found value and determines its location.
Test Retrieves the value specified in the string. Returns TRUE or FALSE.
Search Retrieves a value that matches a regular expression.
Match Finds a match for one or more regular expressions.
Replace Replace the substring that matches the regular expression.
Split Splits a string into an array of strings.

Summary of methods for commonly used JS objects

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.