How can I extract metafields value into a .js file?

How to extract the metafields value to a .js file and assign it to a variable to use it later in the function and check the true false value?

What have you tried so far? Even creating a global var in within the dom would get you to a solution so just want to make sure I’m not repeating things you’ve already attempted.

I would like to set 2 values ​​in metafields true false and assign their value to a variable in js. And then if false do something other than true. Just can’t get metafields value in .js file

I try do something like this:
let foo = {{ variant.metafields.custom.only_onetime_buy_option | json }};
console.log( foo )
but shows me Unexpected token ‘{’