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 contained
xxx.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~+Infinity
The new string after the second repetitionxxx.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 deprecatedsubstring
Instead ofxxx.substring()
, returns the cut string, taking the start and end positionsxxx.toLowerCase()
Literally, lower casexxx.toUpperCase()
“, literally, become uppercase- Converting other objects to strings can be used
toString()
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 objectArray.isArray()
Check if it is an arrayxxx.concat(yyy)
Merging two arrays returns a new array, the nested array preserves the referencexxx.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 donexxx.values()
Returns an Array Iterator containing the values of each indexxxx.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 argumentxxx.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 everyxxx.forEach
Returns undefined, returns undefined, and returns a callback to each element of the arrayxxx.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 callxxx.includes()
To determine if there is a given value in the array, the second argument specifies the starting position for the searchxxx.indexOf()
Finds the subscript of a given element, returns -1 if none existsxxx.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 passedxxx.unshift()
, adds one or more elements to the beginning of an array and returns the new length of the arrayxxx.shift()
Removes the first element from the array and returns the value of the element, changing the array lengthxxx.pop()
Delete the last element in the array and return the value of that element, changing the array lengthxxx.push()
Adds one or more elements to the end of the array and returns the new length of the arrayxxx.keys()
, returns a value containing each index key in the containing arrayArray Iterator
Object.xxx.reverse()
Reverse the array, change the array, and return the same reference addressxxx.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 elementsxxx.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