I'm kinda lost in figuring out the logic for javascript.
Currently, I'm extracting every element and pushing them into an array.
I'm having a hard time when I want to access the object element.
This is the data in the text file:
1#1#test#Tombstone#8#Yes
2#3#test2#Tombstone3#81#Yes
When I access the first array rowCells[0] . It returns me
1
2
which is the first column itself.
I was hoping for it to return the first row. The intended functionality is as follows:
1- Push everything to an array
2- Giving element key like first column is no,type,header,content,score
3- Search all the row based on the element key such as type=2
4- Search based on the type and no, then show the content.
Any suggestions? Thanks 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>';
for (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>