// list數(shù)組轉(zhuǎn)tree數(shù)組
function list2Tree(list, keyName, keyPname, keyValue = '') {
let children = list.filter(item => item[keyPname] == keyValue);
return children.map(item => {
item.children = list2Tree(list, keyName, keyPname, item[keyName]);
return item;
})
}
// tree數(shù)組轉(zhuǎn)list數(shù)組
function tree2list(tree) {
const list = []
const queue = [...tree]
while (queue.length) {
const node = queue.shift()
const children = node.children
if (children) {
queue.push(...children)
}
list.push(node)
}
return list
}
// 隨機(jī)字串
function randomString(len) {
len = len || 8;
let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默認(rèn)去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
let maxPos = $chars.length;
let str = '';
for (let i = 0; i < len; i++) {
str += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return str;
}
// queryString轉(zhuǎn)化成對象
function param2Obj(url) {
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
if (!search) {
return {}
}
const obj = {}
const searchArr = search.split('&')
searchArr.forEach(v => {
const index = v.indexOf('=')
if (index !== -1) {
const name = v.substring(0, index)
const val = v.substring(index + 1, v.length)
obj[name] = val
}
})
return obj
}
util函數(shù)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 在這個(gè)java15都出來了的年代,我偶爾還能聽到一種說法叫java8新特性,有點(diǎn)太扯了?,F(xiàn)在的程序員必要技能:la...
- kubernetes 版本基于1.5.0, 版本升級很快,但是應(yīng)該過程都差不多 文件夾解釋 /kubernetes...
- 1.0 當(dāng)然,這些都只是拋磚迎玉的皮毛。 但是,所謂“見微知著”,通過查閱API文檔,并結(jié)合本篇中的示范代碼,做到...
- java.util.Arrays 類就是為數(shù)組而生的專用工具類,基本上常見的對數(shù)組的操作,Arrays 類都考慮到...