Javascript 如何将时间戳放入本地存储?

Javascript 如何将时间戳放入本地存储?,javascript,json,google-chrome-extension,timestamp,local-storage,Javascript,Json,Google Chrome Extension,Timestamp,Local Storage,您好,我正在创建一个chrome扩展,我正在尝试将访问url后检索到的所有时间戳放入本地存储中的数组中,但我在这样做时遇到了问题。它会继续更新时间戳,我希望所有的时间戳保持不变。然而,它似乎没有保存任何东西,我一直收到这个错误。是否有人知道如何修复此错误或可能导致此错误的原因 修正第5行的打字错误:日期>>>数据 var数据=[]; data=JSON.parse(localStorage.getItem('session'))| |[]; //将新数据(无论是对象还是其他任何数据)推送到阵列

您好,我正在创建一个chrome扩展,我正在尝试将访问url后检索到的所有时间戳放入本地存储中的数组中,但我在这样做时遇到了问题。它会继续更新时间戳,我希望所有的时间戳保持不变。然而,它似乎没有保存任何东西,我一直收到这个错误。是否有人知道如何修复此错误或可能导致此错误的原因


修正第5行的打字错误:日期>>>数据

var数据=[];
data=JSON.parse(localStorage.getItem('session'))| |[];
//将新数据(无论是对象还是其他任何数据)推送到阵列上
data.push(Date.now());
setItem('session',JSON.stringify(data));
myDate=数据;
//输入数据
时间=我的日期;

localStorage.getItem('session')是什么
?你能给我们展示一下更多的背景吗?错误的图像反映了在forEach中正在进行解析call@Taplar我添加了更多的上下文并修复了打字错误。它位于函数addrow()中。我仍然收到相同的错误,并且我的“会话”中当前没有任何内容。
function addRow() {

    //SavaDataToLocalStorage(data);
    
        //putting dates in array-- works somewhat
            
            
            //var myDate = data[data.length-1];
            //data.length = 0;
    
    const bg = chrome.extension.getBackgroundPage()    
    Object.keys(bg.get).forEach(function (url) {
    
    
        // Append product to the table
            var data = [];
            data = JSON.parse(localStorage.getItem('session')) || [];
            // Push the new data (whether it be an object or anything else) onto the array
            data.push( Date.now() );
            localStorage.setItem('session', JSON.stringify(data));
            myDate = data;
        
            //protocol
            var arr = url.split("/");
            var protocoll = arr[0] + "//" + arr[2];
        
            //inputed data --
            browser= "Google Chrome"; 
            protocol = protocoll;
            downloads = "example";
            description = "example";
            //use data or myDate as time
            time = myDate;
            //have as Date.now()
                
        
        //will put dates in array and replace it and have var as myDate
    // add new row to the table
                  //1 = in the top 
                  //table.rows.length = the end
                  //table.rows.length/2+1 = the center 

            var newRow = table.insertRow(0);
            
            //console.log(table.rows.length) gives length of table
                  
                  // add cells to the row
                  var browserCell = newRow.insertCell(0);
                  var timeCell = newRow.insertCell(1);
                  var urlCell = newRow.insertCell(2);
                  var protocolCell = newRow.insertCell(3);
                  var downloadsCell = newRow.insertCell(4);
                  var descCell = newRow.insertCell(5);
                  
                  // add the data to the cells
                  
                  urlCell.innerHTML = `${url}`; 
                  timeCell.innerHTML = time;
                    browserCell.innerHTML = browser;
                    descCell.innerHTML = description;
                    protocolCell.innerHTML = protocol;
                    downloadsCell.innerHTML = downloads;
                  console.log("add row works");
     }) 
            }