Trying to add custom code that splits a metafield string into an array

I cant sort of get it working with this online code I found


which successfully splits the simple string

Okay so now the problem.. the string I’m trying to split is a metafield i created “product.metafields.year_n.year_k.value” and I can’t find any way to basically swap the plain text string “One, Two, Three” with the metafield string


Why doesn’t this work?

Hi @Frustration ,

Variable ‘product.metafields.year_n.year_k’ has a value of a string separated by ', '?

Can you send me the value of this: {{ product.metafields.year_n.year_k.value }}

Hope it helps!

Thank you for the reply!
To give a bit more detail I’m setting up a search using metafields. A lot of my products have a year range so I was hoping I could add something like “2001, 2002, 2003, 2004, 2005” in the metafield box on the backend product page and this code would take that string and separate them into individual values on a drop down menu.

This is current code


And what it does

I’m not sure why its not separating them but it does remove the comma I guess..

Hi @Frustration ,

Please change code:


Hope it helps!

Wow this is perfect! Thank you so much.