How to use fetch in a function?

<!DOCTYPE html>
        #button {
            width: 250px;
            height: 50px;
            border: 1px solid black;
            text-align: center;
            vertical-align: middle;
            font-size: 32px;
        <button id="button" type="button" onclick="OnClick()">Show Data</button>
        function OnClick() {
                .then(res => res.json)
                .then(data => {

I try to make a function that data will show out when I click the button, but the console respond” f json() { [native code] }. How to fix this error