1.[{limit:20},{offset:0}]
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 res = arr.map(item=>{
var obj = {};
obj[item.split("=")[0]] = item.split("=")[1];
//item = [limit,20]
return obj;
})
console.log(res)
2.{limit:20,offset:0}
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=>{
// item = [limit,20]
obj[item.split("=")[0]] = item.split("=")[1];
})
console.log(obj)
3.颠倒
var arr = "hello world";
var str = arr.split("").reverse().join("");
console.log(str)
4.去重
var arr = [1,2,1,4,5,6,4];
var result = [];
arr.forEach(item=>{
if(!result.includes(item)){
result.push(item)
}
})
console.log(result)
var arr = [1,2,3,2,4,4,5]
var s = new Set(arr)
console.log([...s]) 展开