嘗試在一個新匹配中使用匹配函數的結果時出現問題。JavaScript中的重複匹配
這是代碼:
<html>
<body>
<script type="text/javascript">
p="somelongtextmelongtextmelongtextmelongtext";
f1 = p.match(/some/g);
document.write(f1);
f2 = f1.match(/om/g);
document.write(f2);
</script>
</body>
</html>
輸出是單詞「一些」時,它必須是「嗡」。我不明白這種行爲,我需要在更復雜的情況下輸出f1。
在此先感謝。
是的。這就是代碼。我很困惑,因爲我總是看到結果是一個字符串,因爲格式是match1,match2等......和document.write(f1);顯示有效的輸出而不使用數組格式。非常感謝你。 – Memochipan
使用控制檯比使用document.write測試東西要好。它會顯示一個數組,而不是數組的toString()等價物。 – epascarello
編輯我的答案使用'console.log' per @ epascarello的評論 – digitalbath