I am problem with using === to compare string I get whole data from text file and split value line by line with ('\n') like readLine() in java and want to find string "SECTION" but can't find.
when i put
if(contents[i] === "SECTION") {
alert("This is section");
}
no alert! I am sure text file have word "SECTION"
but
if (contents[i].match("SECTION))
is work.
any suggestion ? thanks
javascript
function readFile (evt) {
var files = evt.target.files;
if (files) {
for (var i=0, f; f=files[i]; i++) {
var file = files[i];
var reader = new FileReader();
reader.onload = function() {
var contents = [];
contents = this.result.split("\n");
for (var i = 0; i < contents.length; i++) {
if(contents[i] === "SECTION") {
alert("This is section");
}
document.getElementById('textArea').innerHTML +=contents[i];
}
}
reader.readAsText(file);
}
}
}