Using JS to trim datalayer variable

I was able to get the value from a dataLayer variable, but i’d like to trim the value. It’s for ecommerce and pricing.
For example: price is “9 EUR”. But I want to trim the value to “9” to use in my purchase snippet. Is this possible somehow?

I tried to use a placeholder in my JS variable, but that breaks the debug script. See my other post: No preview mode - SyntaxError in console - #2 by Lukas

Does this solve your issue?

I found the solution myself. Instead of trying to use a placeholder in my purchase script. I directly used JS to get the variable and edit it in the same script.

var addPrice = dataLayer[dataLayer.length -1][‘ecommerce’][‘add’][‘products’][‘0’][‘price’];
var priceShort = addPrice.substring(0, addPrice.length - 4);

1 Like