How to delete all cookies using Java Script

Here is a simple small function to delete all cookies using java script.You have to only call to this function.You can test this using firebug console.You can only remove cookies created by JavaScript.If a cookie was create by the server, then you cannot remove it through JavaScript.

function deleteAllCookies() {
    var cookies = document.cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}

This is a another method to delete cookies.

function deleteAllCookies() {
    var cookies = document.cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
      eraseCookie(cookies[i].split("=")[0]);
    }
}