1. split( ) && join( )
var str = "hello"
// [h,e,l,l,o]
// [o,l,l,e,h]
// olleh
var arr = str.split("");// 将字符串分割为数组
console.log(arr); // ["h","e","l","l","o"]
arr.reverse()
console.log(arr); // ["o","l","l","e","h"]
var s = arr.join("")
console.log(s); // 将数组转为字符串
2、格式转换
var http = "https://192.168.4.18?limit=20&offset=0"
// [{limit:20},{offset:0}]
var arr = http.split("?")[1].split("&")
var res = arr.map(item=>{
var obj = { }
obj[item.split("=")[0]]=item.split("=")[1]
return obj
}
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)