mardi 29 mars 2016

Remove an object from an array on a condition

I have a csv file that I've already splitted by line breaks and I've broken it down even more by the commas in the line breaks to give me three things I'm looking for and named them for later use in the program. What I'm looking to do is remove an item if a one of the objects match a certain value.

var values=[];
var output="";
for(i = 0; i < csv_split.length; i++){
    csv_split[i] = csv_split[i].split(',') //Splits the csv file that's already split by new line by commas
                 values[i]={}
    values[i].Name=newline_split[i][1]; //finds the second object and names it values.name
    values[i].Rev=newline_split[i][2]; //finds the third object and names it values.rev
    values[i].URL=newline_split[i][9]; //finds the eighth object and names it values.url
}

This then is used later so I can get a list of just the values I'm looking for.

    for (i=0; i < values.length; i++){
output += values[i].Name + ',';
output += values[i].Rev + ',';
output += values[i].URL+ ',';
output += "\n\n||||||";
}

So what I did was modified this code to the first for loop:

    if (values[i].Rev == "NO ACCESS") {
csv_split[i].splice(0,1);
}

The idea behind this was that if the values.Rev matched to "NO ACCESS" it would remove the entirety csv_split[i], so that later it wouldn't display it in the output.

Running the script now gives the entire output of regardless if values.Rev matches "NO ACCESS" or not. What am I missing with this?

Aucun commentaire:

Enregistrer un commentaire