JSFiddle - React, Tailwind, and code Playground

by Stéphane Cabaret

HTML

<table id="answered">
<tbody>
    <tr>
      <td data-id="user.email">[email protected]</td>
      <td data-id="meme.yodawg">Yo Dog! I Heard you liked answers, so I answered your question, with a method wrapped in a jQuery plugin!</td>
    </tr>
</tbody>
</table>

JavaScript

(function($) {

  $.extend($.fn, {

    tableRowsToJSONWithFilter : function (filter) {
      var tableSelector = this, item, attr, data, _JSON = [];
      if (typeof(tableSelector) !== 'object') {
        return new Error('Invalid tableSelect!');
      };
      $(tableSelector, 'tr').each(function(index, tr) {
        item = {};
        $('td', $(this)).each(function(index, td) {
          attr = $(td).attr('data-id');
          data = $(td).text();
          if (attr !== undefined && data !== '' && filter && new RegExp(filter, 'i').test(attr)) {
            item[attr] = data;
          };
        });
        _JSON.push(item);
      });
      return _JSON;
    }

  })

})(jQuery);

var json = $('#answered').tableRowsToJSONWithFilter('yodawg');

(typeof(console) !== undefined) ? console.log(json) : {};