JSFiddle - React, Tailwind, and code Playground

by suresh Babu

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<button id="set">Set</button>

JavaScript

var itemKey = 'logger';

function showItem() {
    var value = localStorage.getItem(itemKey, 'not set');
    $("#item").text(itemKey + '=[' + value + ']');
    console.log(value === undefined, value === null);
}

showItem();

$("#set").click(function () {
    if (localStorage !== undefined) {
        var mycars = new Array();
        mycars[0] = "Saab";
        mycars[1] = "Volvo";
        mycars[2] = "BMW";
        localStorage["mycars"] = JSON.stringify(mycars);
        var cars = JSON.parse(localStorage["mycars"]); 
        cars.push('aa')
        console.log(cars);
        alert(cars)
        showItem();
    }
});