mình đang học javascript trên w3school có đoạn code như sau
<!DOCTYPE html>
<html>
<body>
<p id="p1">Please locate where 'locate' occurs!.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = document.getElementById("p1").innerHTML;
var pos = str.indexOf("locate");
document.getElementById("demo").innerHTML = pos;
}
</script>
</body>
</html>
xin hỏi là tại sao khi chạy nó lại trả về giá trị là 7
trên đó họ có nói như thế này à
“The indexOf() method returns the index of (the position of) the first occurrence of a specified text in a string:”

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?