JSFiddle - React, Tailwind, and code Playground

HTML

<button id="player1Link">CLICK ME</div>

JavaScript

var chosenPlayerId = 1;

$("#player1Link").click(function() {
    if (localStorage.getItem("player1Favourite") !== null) {
        var a = JSON.parse(localStorage.getItem('player1Favourite'));
        if (a.indexOf(chosenPlayerId) === -1) {
            a.push(chosenPlayerId);
            localStorage.setItem('player1Favourite', JSON.stringify(a));
            alert("Pushed in");
        } else {
            alert("Already in favourites");
        }
    } else {
        var a = [];
        a.push(chosenPlayerId);
        localStorage.setItem('player1Favourite', JSON.stringify(a));
    }
})