Wrap array operation result string inside another string
Use JavaScript's array methods to your advantage and solve you problem the functional way:

const generate_list_data_attribute = (attribute_name, from_array) =&gt; {
  const string = from_array.map(element =&gt; `"${element}"`).join(",")
  return `data-${attribute_name}="[${string}]"`
}