前端获取cookie的代码解析

//TODO:前端javascript 获取cookie 值 解析
var mycookie = 'k1=v1; k2=v2; k3=v3'
var cuts = mycookie.split(';')
console.log(cuts)
for(var i =0; i<cuts.length; i++){
    //trim() 去掉 字符内容的前后空格
    var c = cuts[i].trim()
    console.log(c)
    var subc = c.split('=')
    console.log(subc)
    if (subc[0] == 'k2')
        console.log('找到k2 == ',subc[1])
}

你可能感兴趣的:(前端获取cookie的代码解析)