Like explained in a similar Stack Overflow question, in vanilla JavaScript, I can do the following:
var data = Object.assign({}, element.dataset);
... in order to get all data-*
attributes as an object.
However, the resulting object is not a "real" JSON object, booleans and numbers are surrounded by quotes.
<div id="my-element"
data-string="It's OK."
data-bool="true"
data-number="10">
</div>
Here is the comparison between vanilla JavaScript and jQuery:
I supposed that in jQuery, jQuery('#my-element').data()
is doing the heavy job of "lifting" the data before returning the actual JSON.
Since I'd like to use ES6 and not jQuery, and I don't want to reinvent the wheel (parsing that values using regex/conditions), I'm asking if there is a quick way to do this job.