首页 > 解决方案 > localstorage.getItem 只显示一个数据,尽管数组中有多个数据

问题描述

尽管数组项数组中存储了多个数据,但它仅显示最近添加的数据。这可能是什么原因?预先感谢您对我们的支持

    // List items
    const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");

    array_item.forEach(function(item,index,array){
        const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
        console.log(array);
        document.getElementById("mark").innerHTML = output;
    });

标签: javascriptarraysjsonlocal-storage

解决方案


const array_item = JSON.parse(localStorage.getItem("array_item") || "[]");

    array_item.forEach(function(item,index,array){
        const output = '<div class="bg-card p-2" style="font-size:14px;"><div class="container"><strong>Okunmadı olarak işaretlediğin makale:</strong> <a href="<?=PROOT?>home/details/'+item.sef_link +'">'+item.title+'</a></div></div>';
        console.log(array);
        document.getElementById("mark").innerHTML += output;
    });

推荐阅读