split() function explanation

const str = 'h i'

Define a constant str as a string hi

str.split() This is to split the string directly as a whole and the output result is an array ['hi']

str.split('') with a single quote means that every character in the string, including spaces, is converted into each element in the array.

reverse() means to reverse the elements, that is, to re-arrange the elements in the array in reverse order

Here's the join() function to explain

const fruits = ["banana","apple","orange"]
console.log(fruits.join("and"))

Output: banana and apple and orange

This is the split array

join() converts the array to a string, the default is to use commas to separate

If it is replaced with other delimiters, such as and the string converted from the linked array, the expression is: join("and")

Guess you like

Origin blog.csdn.net/m0_56349322/article/details/123952895