Basic types of

1. The string

  • Returns the length of the string:xxx.length
  • Returns the character at the specified position:xxx.charAt(), the default is 0
  • Concatenates the string and returns a new string
let str1='I love '
let str2='you! '
let wholeStr=str1.concat(str2)
console.log(wholeStr)

// A new variable needs to be created to receive the concatenation result
Copy the code
  • Checks whether a character is containedxxx.includes(), two arguments: the string to search for and the starting position, 0 by default
  • Find the index of a given character in the string, return -1 if no,xxx.indexOf(), two arguments: specifies the string to look for and the starting position, 0 by default. You can also uselastIndexOf()Returns the index of the last found given value
  • xxx.match(), using a regular expression, returns an array object containing the searched value. If you take a non-regular expression object as a parameter directly,
  • xxx.repeat(), returns the specified string0~+InfinityThe new string after the second repetition
  • xxx.slice()The cut string returns the cut part with two arguments: the start position and the end position
  • Xxx.split () splits a string. The first argument can be a string or a re. The second argument is an integer, indicating how many times to split the string'1 2 3 4 5 6'.split(' ',2)If you split it twice, you only get the first two terms back[' 1 ', '2']
  • xxx.substr()Returns the cut string. The arguments are the starting position and the cut length. This string may be deprecatedsubstringInstead of
  • xxx.substring(), returns the cut string, taking the start and end positions
  • xxx.toLowerCase()Literally, lower case
  • xxx.toUpperCase()“, literally, become uppercase
  • Converting other objects to strings can be usedtoString()orString(xxx)And recommendedString(xxx)

The complex type

An array of 1.

  • Array.from()To create a new, shallow-copy instance of an array-like or iterable object
  • Array.isArray()Check if it is an array
  • xxx.concat(yyy)Merging two arrays returns a new array, the nested array preserves the reference
  • xxx.entries()Returns an Array Iterator object withnext()Method, called once, returns an object with a value attribute that retrieves an array of key-value pairs, and a done attribute that is false until next() is done, and true when next() is done
  • xxx.values()Returns an Array Iterator containing the values of each index
  • xxx.every(), tests whether all values of the array can pass the test of a specified function, which is true. Accepts a callback that takes three arguments, the current value, the index subscript, an array that calls every, and a this that points to the argument
  • xxx.map(()=>{})Performs one operation on each element and returns the array after the operation. Parameters withevery()
  • xxx.filter()Filter out the values tested by the callback function and return a new array with the same argument as every
  • xxx.forEachReturns undefined, returns undefined, and returns a callback to each element of the array
  • xxx.reduce(()=>{},0), perform a callback on each element, and the result is summarized into a single return value. It takes a callback and an initial value. The callback takes four arguments, the first to record the result, the second to the current element, the third to the current index, and the fourth to the entire array in the call
  • xxx.includes()To determine if there is a given value in the array, the second argument specifies the starting position for the search
  • xxx.indexOf()Finds the subscript of a given element, returns -1 if none exists
  • xxx.join(), converts all the elements in the array to strings, concatenates them with delimiters, and returns a string. Accepts a delimiter argument, or a comma if no argument is passed
  • xxx.unshift(), adds one or more elements to the beginning of an array and returns the new length of the array
  • xxx.shift()Removes the first element from the array and returns the value of the element, changing the array length
  • xxx.pop()Delete the last element in the array and return the value of that element, changing the array length
  • xxx.push()Adds one or more elements to the end of the array and returns the new length of the array
  • xxx.keys(), returns a value containing each index key in the containing arrayArray IteratorObject.
  • xxx.reverse()Reverse the array, change the array, and return the same reference address
  • xxx.sort(), accepts a comparator function that, if not passed, sorts the characters by their Unicode loci in the converted string. This is what happens when you pass the comparator function
let xxx=[1234.234.345.3465.456]
If a is less than 0, a is in front of B, which is equal to 0, and if b is greater than 0, b is in front of A
xxx.sort((a,b) = >{
   if(a<b){
     return -1
   }
   if(a>b){
     return 1
   }
   return 0
})
Copy the code
  • xxx.splice(), delete or replace an existing element, and return the modified contents, changing the original array. It takes three arguments: the starting position, the number of deleted elements, and the replacement elements
  • xxx.slice()Returns a new array object, unchanged from the original array, with two arguments: start position and end position.

2. The object

/ / to be added