How to optimize Cookie Parsing? I have written this code for cookie parsing. Can anyone tell me what optimizations we can do in this or what can we do to make it more concise? 

function parseCookies(cookies) {
  var cookie,
    cookieParts,
    parsedCookies = [];

  if (!cookies || !cookies.length) {
    return null;
  }

  // Remove domain from each cookie to decrease the size of cookie (Not needed)
  for (var i = 0; i &lt; cookies.length; i++) {
    cookie = cookies[i];
    cookieParts = cookie.split(';');

    for (var index2 = cookieParts.length - 1; index2 &gt;= 0; index2--) {
      var pair = cookieParts[index2],
        key = pair.split('=')[0];

      if (key &amp;&amp; key.trim().toLowerCase() == 'domain') {
        cookieParts.splice(index2, 1);
      }
    }

    cookie = cookieParts.join(';');
    parsedCookies.push(cookie);
  }

  return parsedCookies;
}
Like I wrote in my comment, the function you've got isn't really a parser. Yes, it parses the strings you pass it, but that's not its purpose, as far as I can tell. Parsing is a byproduct of the actual purpose, which seems to be to sanitize the strings by removing the domain key/value pair.

Now, if you're just looking to remove that key/value pair, you could simply do

function sanitizeCookies(strings) {
  return strings.map(function (cookieString) {
     return cookieString.replace(/\bdomain\s*=[^;]*;?/ig, "");
  });
}


Like @tomdemuyt, I'm using Array.map() so you won't get null back if you pass it an empty array; you'll just get another empty array (and, frankly, that makes more sense, I think).