To get the number of links in JavaScript, use the links property with length property.
Example
You can try to run the following code to display the number of links in a document −
<!DOCTYPE html>
<html>
<body>
<a href="https://www.tutorialspoint.com/php">PHP</a>
<br>
<a href="https://www.tutorialspoint.com/java/">Java</a>
<br>
<a href="https://www.tutorialspoint.com/html5/">HTML</a>
<br>
<a href="https://www.tutorialspoint.com/css/">CSS</a>
<script>
var val = document.links.length;
document.write("<br>Number of links in the document: "+val);
</script>
</body>
</html>