js清除全部cookie

【js清除全部cookie】试了很多网上写的清除cookie的代码,逻辑是将cookie有效期设为过期时间,但是没有效果,最后发现还要再加个max-age=0

const clearCookie = () => { var keys = document.cookie.match(/[^ =; ]+(?==)/g); if (keys) { for (var i = keys.length; i--; ) { document.cookie = keys[i] + "=0; expires=" + new Date(0).toUTCString() + "; max-age=0"; } } };

    推荐阅读