I had to extract data from an external file.

On the server-side that’s easy. For example with PHP, file_get_contents('file.html') will store the contents of file.html into a string.

But what about the front-end? Is there an equivalent of file_get_contents in JavaScript?

Actually, this can be easily achieved using fetch:

fetch('/wp-content/themes/theme-name/file.html')
	.then((resp) => resp.text())
	.then(function (data) {
		// Page content is available as 'data'.
	});