Array an Array

Array stack method:

push()

  • Grammar: arrayObject.push(newele,1,newele2,… nexeX)
  • Function: Appends its argument order to the end of an arrayObject
  • The return value:
  • The new length of the array after the specified value is added to it

unshift()

  • Grammar: arrayObject.unshift(newele,1,newele2,… nexeX)
  • Function: Appends its argument sequence to the beginning of an arrayObject
  • The return value:
  • Adds the specified value to the new length of the array

pop()

  • Grammar: arrayObject.pop(a)
  • Function: Deletes the last element of an arrayObject
  • The return value:
  • The element that was deleted

shift()

  • Grammar: arrayObject.shift(a)
  • Function: Delete the first element of an arrayObject
  • The return value:
  • The element that was deleted

Array conversion method:

join()

  • Grammar: arrayObject.join(separator)
  • Parameters:
  • The separator is optional. Specifies the delimiter to use. If this parameter is omitted, a comma is used as a delimiter.
  • Function: Put all the elements of an array into a string.
  • The return value:
  • string
var fruits = ["Banana"."Orange"."Apple"."Mango"];
var energy = fruits.join(); // Banana,Orange,Apple,Mango
var energy = fruits.join(" and "); // Banana and Orange and Apple and Mango
Copy the code

Array reorder method:

reverse()

  • Grammar: arrayObject. Reverse ()
  • Reverse the order of elements in an array
  • The return value:
  • An array of

sort()

  • Grammar: arrayObject.sort(sortfunction)
  • Function: Sort the elements of an array
  • The return value:
  • The reference to the original array, the original array, will be changed
  • Description:
  • The sort() method compares strings.
  • 2. The sort() method takes a comparison function as an argument
  • Parameters:
  • Sortfunction: is a function
  • Function takes two arguments, representing two items of an array, and compares two items of an array. If the return value is 1, the value is swapped; otherwise, the value is not swapped
  • Ascending sort:arrObject.sort(fuction(a,b){return a-b; })
  • Descending sort:arrObject.sort(fuction(a,b){return b-a; })
  • When a==b, the return value is 0, and a and B do not switch places
  • When a>b, the return value is 1, and a comes after B
  • When a

Array manipulation methods

concat()

  • Grammar: arrayObject.concat(arrayX,arrayX,…. arrayX)
  • Function: Connect two or more arrays.
  • The return value:
  • New array

slice()

  • Grammar: arrayObject.slice(start,end)
  • Function: Returns a selected element from an existing array
  • Parameters:
  • Start (required) specifies where to start the selection, if negative, from the end of the array.
  • End (optional) specifies where to end the selection (excluding the element) and is the array subscript at the end of the array fragment. If not specified, all elements from start to end. If this parameter is negative, it indicates the penultimate element in the original array to end the extraction.
  • The return value:
  • The new array

Note: When calculating negative values, you can use: array length plus the number to determine the corresponding position

splice()

  1. delete
  • Grammar: arrayObject.splice(index.count)
  • Parameter: index is the index to be deleted from where, count is the number of deleted
  • Delete zero or more elements starting at index
  • The return value:
  • A new array containing deleted elements
  • Description:
  • Count is the number of items to delete, and if set to 0, items will not be deleted.
  • If this parameter is not set, all values starting from index are deleted.
  1. insert
  • Grammar: arrayObject.splice(index,0,item1,…… ,itemX)
  • Function: Inserts a value at the specified position
  • Parameters:
  • Index: indicates the start position
  • 0: indicates the number of items to be deleted
  • item1… ItemX Specifies the item to insert
  • Return value: new array
  1. replace
  • Grammar: arrayObject.splice(index,count,item1,…… ,itemX)
  • Function: Inserts a value at a specified location and deletes any number of items at the same time
  • Parameters:
  • Index: indicates the start position
  • Count: number of items to be deleted

Array position methods:

indexOf()

  • Grammar: arrayObject.indexOf(searchValue,startIndex)
  • Function: Searches backwards from the beginning of the array (position 0)
  • Parameters:
  • Searchvalue: Required, the item to find
  • StartIndex: Optional, index at the starting position (default: 0)
  • The return value:
  • Number, the position of the item in the array, returns -1 if not found

lastindexOf()

  • Grammar: arrayObject.lastIndexOf(searchValue,startIndex)
  • Search forward from the end of the array
  • Parameters:
  • Searchvalue: required, the item to find;
  • StartIndex: Optional, index at the starting position, starting with index 0 (default: all)
  • The return value:
  • Number, the position of the item in the array, returns -1 if not found

String String

charAt()

  • Grammar: stringObject.charAt(index)
  • Function: Returns the character at the index position in stringObject

Return value: the character searched

charCodeAt()

  • Grammar: stringObject.charCodeAt(index)
  • Function: Returns the Unicode encoding of the index position character in stringObject

Return value: Uniconde encoding of the character searched

String position method

indexOf()

  • Grammar: stringObject.indexOf(“o”)
  • Function: Searches for a given substring from a string, returns the position of the substring.
  • Return value: value
  • Note: If the string is not found, -1 is returned

lastIndexOf()

  • Grammar: stringObject.lastIndexOf(“o”)
  • Function: Searches a string from back to front. Searches a given substring within a string. Returns the position of the substring calculated from the starting position (0).
  • Return value: value
  • Note: If the substring is not found, -1 is returned

String interception method

slice()

  • Grammar:
  • stringObject.slice(start,end)
  • Function:
  • Intercept string
  • Parameter Description:
    1. Start: Required, specifies the start position of the substring.
    1. “End” : indicates the end of the string. The end is not included in the interception range and is omitted to the end of the string.
    1. When the slice argument is negative, the value is the string length + the negative number.
  • Return value: Extracted string
  • subString()

  • The syntax and function are the same as slCIE. Return value consistent
  • The difference is:
  • 1. When the parameter is negative, the parameter is automatically converted to 0.
  • 2. Substring () starts with a smaller number and ends with a larger number.

substr()

  • Grammar: stringObject subStr (start, len)
  • Function consistent with Slice return value
  • Parameters:
  1. Start: Required, specifies the start position of the string
  2. Len: Optional, indicates the total number of truncated characters. If omitted, truncated to the end of the string.
  3. When start is negative, the negative value passed in is added to the length of the string.
  4. Returns an empty string when len is negative

Other string methods:

split()

  • Grammar: stringObject. Split (separator)
  • Function: Split characters into string arrays
  • Return value: Split array
  • Separator: Required, delimiter

replace()

  • Grammar:
  • stringObject.replace(regexp/substr,replacement)
  • Function:
  • Replace some characters in a string with other characters, or replace a substring that matches the regular expression book.
  • Return value: the replaced string
  • Parameters:
  • Regexp: required. The RegExp object that specifies the pattern to replace the substring.
  • Replacement: required. A string value.

toUpperCase()

  • Grammar: stringObject toUpperCase ()
  • Function: Convert a string to uppercase
  • Return value: uppercase string

toLowerCase()

  • Grammar: stringObject toLowerCase ()
  • Function: Convert a string to lowercase
  • Return value: Lowercase string

Math Math

min()

  • Grammar: Math. Min (num1, num2… numN)
  • Function: find the minimum value in a group of numbers
  • Return value: Number
  • max()

  • Grammar: Math. Max (num1, num2… numN)
  • Function: find the maximum value in a group of numbers
  • Return value: Number

ceil()

  • Grammar: Math. Ceil (num)
  • Function: Round up, that is, return the smallest integer greater than num
  • The return value: Number

floor()

  • Grammar: Math. Floor (num)
  • Function: Round down to return the integer part of num
  • The return value: Number

round()

  • Grammar: Math. Round (num)
  • Function: Round values to the nearest whole number
  • The return value: Number

abs()

  • Grammar: Math. Abs (num)
  • The absolute value of num is returned
  • The return value: Number

random()

  • Grammar:
  • Math.random()
  • Function: Returns a random number greater than or equal to 0 and less than 1
  • Return value: Number
  • Description:
  • The formula for finding random integers between n and m:
  • random = Math.floor(Math.random()*(m-n+1)+n)

Time to Date

getFullYear()

  • Grammar: Date. GetFullYear ()
  • Function: Returns a 4-digit year
  • Return value: a 4-digit number representing the year
var d = new Date(a);var n = d.getFullYear(); / / 2021
Copy the code

The syntax for the following methods is the same as above

getMounth()

Syntax: getMounth() : returns the number of months from 0 to 11

getDate()

GetDate () : Returns the day of the month

getDay()

GetDay (): returns the week and the value is 0-6

getHours()

GetHours () : Returns the hour

getMinutes()

GetMinutes () : Returns the score

getSeconds()

GetMinutes () : Returns seconds

getTime()

GetTime () : Returns the number of milliseconds representing the date

JSON

JSON.parse()

  • Grammar:JSON.parse(text[,reviver])
  • Parameters:
  • Text: A valid JSON string is required
  • Reviver Optional, a function that transforms the result and will be called for each member of the object
  • Function: Convert JSON string to JSON object

JSON.stringify()

  • Grammar:JSON.stringify(value[,replacer[,space]])
  • Parameters:
  • Value: JSON object that must be converted
  • Reviver: Optional, a function or array that transforms the result, which will be called for each member of the object
  • Space: Optional, the text is indented, whitespace, and newline characters, or if space is a number, the return value text is indented by a specified number of Spaces at each level.
  • Function: Convert JSON object to JSON string