JSFiddle - React, Tailwind, and code Playground

by lollero

HTML

<div data-name="my div"></div>
<div data-name="a div"></div>
<div data-name="the div"></div>
<div data-name="test"></div>

JavaScript

// Automatically create empty arrays based on the number of divs

var object = {};

$('div').each(function() {

    object[ $(this).data().name ] = true;

});

console.log( object );