JSFiddle - React, Tailwind, and code Playground

by f0t0n

HTML

<div id="holder">
    <form action="" class="dataset">
        <input type="text" data-type="matching" value="10">
        <input type="text" data-type="growth" value="10">
        <input type="text" data-type="other" value="10">
        <input type="text" data-type="growth" value="20">
        <input type="text" data-type="growth" value="15">
        <input type="text" data-type="other" value="30">
        <input type="text" data-type="matching" value="20">
    </form>
</div>

JavaScript

(function() {
    var holder = $('#holder');
    var compoundedObj = {};
    
    $(".dataset input", holder).each(function() {
        var dataType = $(this).data("type");
        if(!compoundedObj.hasOwnProperty(dataType)) {
            compoundedObj[dataType] = 0;
        }
        compoundedObj[dataType] += parseInt($(this).val(), 10);
    });
    
    console.log(compoundedObj);
})();