Q:

How can I make an array based on the cookies?

Here are the browsers cookies:
console.log(document.cookie);
//=> name_instagram=true; name_googleplus=true;

And here is my code:
console.log(document.cookie.split(';').filter( (c) => c.startsWith(parts[1])).map( (d) => d.replace(/.*_(.*)=true/, "$1")));
//=> ["instagram"]

While the expected result is ["instagram", googleplus]. How can I get that?

Currently as you see, just the last item in the cookie will be stored into the array as result value. What's wrong?

A:

After your startsWith filter second item in array will be " name_googleplus=true;", note leading space, so it starts with " name_" instead of "name_". One way to fix it is using trim() to remove whitespaces.
console.log(document.cookie.split(';').filter( (c) => c.trim().startsWith('name_')).map( (d) => d.replace(/.*_(.*)=true/, "$1")));

