JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://jquery-csv.googlecode.com/files/jquery.csv-0.71.min.js"></script>
<button>Run</button>
<div id="names"></div>
JavaScript
var babyCsv = " Bryan, 1, boy, 2010 \n Isabella, 1, girl, 2010 \n Bobby, 2, boy, 2010 \n Sophia, 2, girl, 2010 \n Nina, 5, girl, 2010 \n Alexander, 6, boy, 2010 \n Aiden, 9, boy, 2010 \n Anthony, 10, boy, 2010";
// true csv file with multiple lines uses toArrays
// makes a 2-D JS array -- uncomment below to see output
var data = $.csv.toArrays(babyCsv);
// console.log(data);
$(function () {
$("button").click(function () {
var count1 = 0;
var count2 = 0;
console.log("Num kids: " + data.length);
for (var i = 0; i < data.length; i++) {
name = $.trim(data[i][0]); //name is first column
// log to screen
$("#names").append(name + ',<br /> ');
if (name[0] == "A") {
count1++;
} else if (name[0] == "B") {
count2++;
};
};
console.log("Kids with A or B names: " + (count1 + count2));
});
});