How to get all COOKIES with the NAME beginning with WORD?

When users click "add to favorites" creates a cookie of the form:
name: like_id , where id is any of 1 to 6 digits or 'undefined'
value: 1

Form the link:
site.com?ids=id1+id2+id3

function favorite() {
 var arrCook = document.cookie.split(';');
 var likeCook = arrCook.filter(function(c) {
 return c.trim().indexOf('like_') === 0;
});
 var mapArr = likeCook.map(function(c) {
 var subresult = c.match( /like_(.*)=1/ );
 return subresult[1];
});
 var args = Array.prototype.slice.call(mapArr);
 var result = args.join('+');

 if (result !== ") {
 $("#menu").prepend('<li id="menu_favorite"><a href="http://site.com?ids=' + result + '&favorite">favorites</a></li>');
}
}
favorite();


How to improve the code?
July 8th 19 at 12:10
1 answer
July 8th 19 at 12:12
var newarr=[];
for and condition:
if(typeof COOKIES_list[i].id !== "undefined"){
// COOKIES_list[i].id is not undefined
// push into a new array where the cookie id is undefined
newarr.push(COOKIES[i]);
}

Find more questions by tags HTTP CookiesJavaScript