Да, конечно, возможно, код, который вы разместили, делает это, я знаю, что изначально это может сбить с толку, но позвольте мне объяснить часть JavaScript ...
<script>
// in html you use script tag to put javascript code inside and using jquery, you // can easily modify the html page.
$(document).ready(function() {
// this is a jquery piece of code that is calling an // ajax request
$.ajax({
type: "GET",
url: "B1_1.csv", //read csv file
dataType: "text",
success: function(data) {processData(data);}
});
});
function processData(allText) {
// a method is a piece of code that you write once because you know that you will // reuse it and it makes the code more readable
var allTextLines = allText.split("/\r\n|\n/");
// split is a method that takes as input a string and (in this case `allText`) //literally split the calling string in n strings storing them in an array. The //strings are splitted by the string you passed as parameter. In this case this //piece of code is simply dividing the entire text in n lines
var headers = allTextLines[0].split(',');
// Now is splitting the line number 1 (look for 0-indexed array on google) in many // strings
var lines = [];
for (var i=1; i<allTextLines.length; i++) {
// A for loop is a loop that repeat itself n-times until a condition is no more
// satisfied, in this case i has to be smaller than the length of that array.
// `var i=1` represents the starting point of the index.
// `i<allTextLines.length` is the condition and `allTextLines.length` returns the
// length of the array.
// In the end `i++` just increment i every time the loop reach the end and restart
var data = allTextLines[i].split(',');
if (data.length == headers.length) {
// an if statement is a piece of code that is executed if and only if a condition
// is satisfied.
var tarr = [];
for (var j=0; j<headers.length; j++) {
tarr.push(headers[j]+":"+data[j]);
}
lines.push(tarr); // The push method add to an array a new element
}
}
}
</script>
Я пытался объяснить как можно лучше (я плохой учитель, так что это тренировка для меня, ахах), я надеюсь, что помог тебе. Если у вас есть какие-либо сомнения, просто спросите, и если вы хотите больше узнать о коде, просто посмотрите учебники в Интернете, потому что их много. Может быть, вы заинтересованы, я узнал javascript от здесь лет назад.