JavaScript giving element key to array -


i'm kinda lost in figuring out logic javascript.

currently, i'm extracting every element , pushing them array.

i'm having hard time when want access object element.

this data in text file:

1#1#test#tombstone#8#yes 2#3#test2#tombstone3#81#yes 

when access first array rowcells[0] . returns me

1 2 

which first column itself.

i hoping return first row. intended functionality follows:

1- push array

2- giving element key first column no,type,header,content,score

3- search row based on element key such type=2

4- search based on type , no, show content.

any suggestions? in advance.

<script type="text/javascript"     src="http://code.jquery.com/jquery-1.10.1.min.js"></script>  <script> $.ajax({   url: 'content.txt',   datatype: 'text', }).done(successfunction);   function successfunction(data) {   var allrows = data.split(/\r?\n|\r/);   var table = '<table>';   (var singlerow = 0; singlerow < allrows.length; singlerow++) {     var rowcells = allrows[singlerow].split('#');     //table += rowcells.tostring();      table += '<br>';     var first_word = rowcells;     table += first_word;     }    $('body').append(table); } </script> 

i use split, reduce, split, , join build table.

var str = `1#1#test#tombstone#8#yes  2#3#test2#tombstone3#81#yes`    var rows = str.split(/\n/g).reduce( function (str, row) {    return str + "<tr><td>" + row.split(/#/g).join("</td><td>")  + "</td></tr>";  }, "")    var table = "<table><tbody>" + rows + "</tbody></table>"  $("#out").append(table)
td { border: 1px solid black; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="out"></div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -