Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142239

Where did the extra quotes come from, or Why is this failing?

$
0
0

I'm having a problem with this code shown below in that the .join() isn't working properly due to extra quotes (as far as I can tell anyway). I'm inputting a comma separated list and after the .split(), I'm getting extra quotes around each item in the console for the 'initial' values array like so: ""User"". However, if I console.log the item as I've done with 'test', it comes out like so: "User". That being said, I can't make the evaluation of 'values[i] == "User"', and instead have to write it as I've done in the 'test2' console.log. Normally I would assume that the .split() is the cause, but the documentation for it states that it doesn't change the original string. I'm still pretty much an amateur when it comes to programming, so it's probably staring me in the face. Still, for the life of me, I haven't been able to spot the cause of the problem. Any help would be appreciated, Thanks.

console.log('csv data', csv);
var values = csv.split(',');
console.log('initial', values);
for (var i = 0; i < values.length; i++) {
    console.log('test', values[i]);
    console.log('test2', values[i] == '"User"');
    if (values[i] == '"User"') {
        values.splice(i, 1);
        //fails here. .join below fails to execute properly
        return values.join();
        console.log("values recheck", values);
    }
    console.log('testval', values);
}

Viewing all articles
Browse latest Browse all 142239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>