我認爲這很明顯是我的代碼。比較運算符!==對0
爲什麼我的代碼返回一個完整的字符串,如果我使用!==
運算符?我知道Javascript中的數組從索引0
開始,在這裏我輸入整個文件名作爲參數,因此indexOf(".")
將始終大於0
。不,我沒有在這裏傳遞.htaccess文件。
function getFileExtension(i) {
// return the file extension (with no period) if it has one, otherwise false
if(i.indexOf(".") !== 0) { //
return i.slice(i.indexOf(".") + 1, i.length);
} else {
return false;
}
}
// here we go! Given a filename in a string (like 'test.jpg'),
getFileExtension('pictureofmepdf'); return given string
// both operand are same type and value
但是,如果我改變比較討論,以
(i.indexOf(".") > 0) // logs false
附:我問你是問,這是usvsth3m形式。
如果i> 0,比明顯也不同(不等於)!==到零(0) –
你的問題是什麼? – Pete
你知道0可能是一個有效的索引吧?在javascript中的數組從0開始 – dbarnes