'How to split and take two columns alone in a csv file using Jquery

Html of the page:

    <input type="file" id="fileUpload" />
     <input type="button" id="upload" value="Upload" />
     <hr />
     <div id="dvCSV">
     </div>
     <script type="text/javascript" 
     src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
     <script src="~/js/site.js"></script>

The below Script is bind to the Upload Button it is working fine in splitting the csv

$(function ()
{
$("#upload").bind("click", function ()
{
    var regex = /(.csv)$/;
    if (regex.test($("#fileUpload").val().toLowerCase()))
    {
        if (typeof (FileReader) != "undefined")
        {
            var reader = new FileReader();
            reader.onload = function (e)
            {
                var table = $("<table />");
                var rows = e.target.result.split("\n");
                for (var i = 0; i < rows.length; i++)
                {
                    var row = $("<tr />");
                    var cells = rows[i].split(",");
                    if (cells.length > 1)
                    {
                        for (var j = 0; j < cells.length; j++)
                        {
                            var cell = $("<td />");
                            cell.html(cells[j]);
                            row.append(cell);
                        }
                        table.append(row);
                    }
                }
                $("#dvCSV").html('');
                $("#dvCSV").append(table);
            }
            reader.readAsText($("#fileUpload")[0].files[0]);
        }
        else
        {
            alert("This browser does not support HTML5.");
        }
    } else
    {
        alert("Please upload a valid CSV file.");
    }
});
});

Thing I want to clarify is --- the current script Splits the csv file like as in the linked image...in "var rows"(line 14) [1]: https://i.stack.imgur.com/sxdKs.png

I want to split and Take out the values like this in the below linked image :(done using c#) [2]: https://i.stack.imgur.com/1hwwD.png

So that I can perform an verification check on 2 columns before it goes to splitting fully and displayed in web page ...(like duplicates based on both columns).. ....any help..??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source