JS常用方法

2021-07-21  本文已影响0人  Poppy11

1、数组对象去重

 let map = new Map()
      for (const process of JiraConfigResult) {
        if (!map.has(process?.statusOfProcess?.id)) {
          map.set(process?.statusOfProcess?.id, process)
        }
      }
JiraConfigResult = ([...map.values()])

2、获取url中的Param
例如:localhost:3000?code='123'&name='Liam'

 let str = window.location.search.replace('?', '')
  let arr = str.split('&')
  let obj = {}
  arr.map(e => {
    let key = e.split('=')
    obj[key[0]] = key[1]
  })
  return obj

例如:localhost:3000/#/?code='123'

export function filterUrlParams() {
  console.log("url",window.location.url)
  console.log("hash",window.location.hash.split("?")[1])
  var after = window.location.hash.split("?")[1];
  if (after) {
    var reg = new RegExp("(^|&)" + 'code' + "=([^&]*)(&|$)");
    var r = after.match(reg);
    if (r != null) {
      return decodeURIComponent(r[2]);
    } else {
      return null;
    }
  }
}
上一篇 下一篇

猜你喜欢

热点阅读