Array操作方法和String操作方法比较

Array 的操作方法和 String 的操作方法老是弄混>_<,下面就对于这两个对象的常用操作方法进行比较~~

Array

☞ 操作方法
  1. concat():returns a new array comprised of the array on which it is called joined with the array(s) and/or value(s) provided as arguments.

     var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])
    
  2. slice():returns a shallow copy of a portion of an array into a new array object.→ 切片

     arr.slice([begin[, end]])
    
  3. splice():changes the content of an array by removing existing elements and/or adding new elements.→ 拼接

     array.splice(start, deleteCount[, item1[, item2[, ...]]])
    

String

☞ 操作方法
  1. concat():将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。

     str.concat(string2, string3[, ..., stringN])
    
  2. slice():extracts a section of a string and returns a new string.→ 切片

     str.slice(beginSlice[, endSlice])
    
  3. substr():returns the characters in a string beginning at the specified location through the specified number of characters.(返回一个从指定位置开始的指定长度的子字符串。)

     str.substr(start[, length])
    
  4. substring():returns a subset of a string between one index and another, or through the end of the string.(返回位于 String 对象中指定位置的子字符串。)

     str.substring(indexStart[, indexEnd])
    
☞ 模式匹配方法
  1. match()

  2. search()

  3. replace()

  4. split():通过把字符串分割成子字符串来把一个 String。 对象分割成一个字符串数组。→ 拆分

     str.split([separator][, limit])
    

Scoop It and Enjoy the Ride!
原文地址:https://www.cnblogs.com/Ruth92/p/5704280.html