JSFiddle - React, Tailwind, and code Playground

by Aleksey Karagodnikov

HTML

<table id="loose-weight">
    <thead>
        <tr>
            <th class="weeks-header">
                <div class="text">Неделя</div>
            </th>
            <th class="predefined">
                <div class="text">Вес, кг</div>
            </th>
            <th class="custom">
                <div class="remove"></div>
                <div class="text" contenteditable="true">Объем груди, см</div>
            </th>
            <th class="last">
                <div class="add"></div>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class="week">
                <div class="monday">27.01.14</div>
                <div class="days-divider">—</div>
                <div class="sunday">02.02.14</div>
            </td>
            <td class="predefined">
                <div class="text" contenteditable="true">105.8</div>
            </td>
            <td class="custom">
                <div class="text" contenteditable="true">98</div>
            </td>
            <td class="last"></td>
        </tr>
        <tr>
            <td class="week">
                <div class="monday">03.02.14</div>
                <div class="days-divider">—</div>
                <div class="sunday">09.02.14</div>
            </td>
            <td class="predefined">
                <div class="text" contenteditable="true">105.6</div>
            </td>
            <td class="custom">
                <div class="text" contenteditable="true">98</div>
            </td>
            <td class="last"></td>
        </tr>
    </tbody>
</table>

JavaScript

th = $('#loose-weight').find('tr:first').find('th').not('.last');
tr = $('#loose-weight').find('tr').not(':first');
var items = {};
items.names = [];
items.values = [];
th.each(function () {
    items.names.push($(this).find('.text').text());
});
tr.each(function () {
    var key = $(this).index();
    var td = $(this).find('td').not('.last');
    td.each(function (i) {
        if (typeof items.values[key] === 'undefined') {
            items.values[key] = [];
        }
        if (i === 0) {
            items.values[key].push({
                monday: $(this).find('.monday').text(),
                sunday: $(this).find('.sunday').text()
            });
        } else {            
            items.values[key].push($(this).find('.text').text());
        }
    });
});
console.log(items);
console.log(JSON.stringify(items));