1. split( ) && join( )

  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)
var http = "https://192.168.4.18?limit=20&offset=0"
// {limit:20},{offset:0}
var arr = http.split("?")[1].split("&")   //["limit=20","offset=0"]
var obj = {}
var res = arr.map(item=>{
  obj[item.split("=")[0]] = item.split("=")[1]
}
console.log(obj)