1.[{limit:20},{offset:0}]

  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. //["limit=20", "offset=0"]
  5. var res = arr.map(item=>{
  6. var obj = {};
  7. obj[item.split("=")[0]] = item.split("=")[1];
  8. //item = [limit,20]
  9. return obj;
  10. })
  11. console.log(res)

2.{limit:20,offset:0}

  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. // item = [limit,20]
  7. obj[item.split("=")[0]] = item.split("=")[1];
  8. })
  9. console.log(obj)

3.颠倒

  1. var arr = "hello world";
  2. var str = arr.split("").reverse().join("");
  3. console.log(str)

4.去重

  1. var arr = [1,2,1,4,5,6,4];
  2. var result = [];
  3. arr.forEach(item=>{
  4. if(!result.includes(item)){
  5. result.push(item)
  6. }
  7. })
  8. console.log(result)
  1. var arr = [1,2,3,2,4,4,5]
  2. var s = new Set(arr)
  3. console.log([...s]) 展开