String Common String method

Basic operation

  • string.lengthGet the length of the string
  • string.concat(str1,str2)String splicing
  • string.indexOf(str,index)Returns the string index value, or -1 if there is none

    @ Parameter DescriptionstrFind stringindexStart locating

Substitution, interception

  • string.replace(old,new)String substitution
  • string.substr(start,count)String interception

    @ Parameter DescriptionstartThe starting positioncountIntercept length
  • string.substring(start,end)String interception 2

    @ Parameter DescriptionstartThe starting positionendEnd position

Array Array object method

Basic operation

Same as String method: length indexOf

  • array.isArray(arr)Check whether it is an array
  • array.reverse()Inversion array
  • array.push(value)Add a tail
  • array.pop()The tail to delete
  • array.unshift(value)Add the head
  • array.shift()Remove the head

cycle

  • array.forEach((item,index)=>{})Common loop with no return value
  • array.map((item,index)=>{})Used to modify the current array
  • array.filter((item,index)=>{ retrun xxx })Use to conditionally filter new arrays

other

  • array.sort()The sorting
Array.sort ((a,b)=>{retrun b-a})Copy the code

Data type conversion method

Strings and Arrays

  • String -> Array string.split('-', limit)

    @ Parameter Description

    The '-'Segmentation based on

    limitThe maximum length of the array returned.
  • Array -> String array.join('-')

Strings and Objects

  • String -> Object JSON.parse(str)
  • Object -> String JSON.stringify(obj)
  • Object deep copyJSON.parse(JSON.stringify(obj))

    The principle is converted to a string and then to an object, which never points to the same address

To add…