1、join-split-reverse

  1. var str = "hello"
  2. // [h,e,l,l,o]
  3. // [o,l,l,e,h]
  4. // olleh
  5. var arr = str.split("");// 将字符串分割为数组
  6. console.log(arr); // ["h","e","l","l","o"]
  7. arr.reverse()
  8. console.log(arr); // ["o","l","l","e","h"]
  9. var s = arr.join("")
  10. console.log(s); // 将数组转为字符串

2、切割字符

  1. var http = "https://192.168.4.18?limit=20&offset=0"
  2. // [{limit:20},{offset:0}]
  3. var arr = http.split("?")[1].split("&")
  4. var res = arr.map(item=>{
  5. var obj = { }
  6. obj[item.split("=")[0]]=item.split("=")[1]
  7. return obj
  8. }
  9. console.log(res)
  1. var http = "https://192.168.4.18?limit=20&offset=0"
  2. // {limit:20,offset:0}
  3. var arr = http.split("?")[1].split("&") //["limit=20","offset=0"]
  4. var obj = {}
  5. var res = arr.map(item=>{
  6. obj[item.split("=")[0]] = item.split("=")[1]
  7. }
  8. console.log(obj)