Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:31:34+00:00 2026-05-27T15:31:34+00:00

I have a javascript Array which I am stringifying in order to store it

  • 0

I have a javascript Array which I am stringifying in order to store it in localstorage

console.log(request.keywords.length);
localStorage.keywords = JSON.stringify(request.keywords);

where keywords is javascript array. Here request.keywords.length returns 12 which is number of elements in array.

After retrieving it and parsing it back to JSON

 var keywords = chrome.extension.getBackgroundPage().getItem("keywords");
    var kjos=JSON.parse(keywords);
    console.log(kjos.length);

The length returned is 342 which is the length of whole string. I tried getting type of object via constructor.name property, it gives me string instead of Array.

Any ideas what is going wrong ?

Snippets:
Background.html

 function getItem(key) {
    var value;
    log('Get Item:' + key);
    try {
      value = window.localStorage.getItem(key);
    }catch(e) {
      log("Error inside getItem() for key:" + key);
      log(e);
      value = "null";
    }
    log("Returning value: " + value);
    return value;
  }

/////

chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
localStorage.keywords = JSON.stringify(request.keywords);
}
);

////////////
Popup.js

var keywords = chrome.extension.getBackgroundPage().getItem("keywords");

    var kjos=JSON.parse(keywords); //kjos is a string variable

/////
keywords.js

//keywordsArray is an Array object
    // Message passing to background page
        chrome.extension.sendRequest({message: "setKeywords", keywords: keywordsArray}, function() 
        {
            console.log(keywordsArray);
            console.log("message sent");
          // The data has been sent, we can close the window now.
          //window.close();
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:31:35+00:00Added an answer on May 27, 2026 at 3:31 pm

    You need to use request like this – chrome.extension.sendRequest({message: "setKeywords"..., but for getKeywords operation. Function getItem can not be used for access to a variable of background page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have javascript object which consists of complex array of structures with nested structures
I have a javascript array of Date objects, which I'd like to test for
I have an array of objects which was fetched from a JSON (JSONP) file
I have Javascript array which contains User object. I have created this array from
I have a JavaScript array as below which I need to filter to get
I have an javascript array, which looks like: var styles = new Array(); styles[0]
I have a javascript array (from a yahoo pipe via JSONP ) in which
I have a PHP multidimensional array which will store information depending on parameters input.
I have a JavaScript array which contain the staff's Chinese and English names. Example:
I have a javascript array which defines an infinite tree like this. z=['~GROUPHEAD 0~',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.