1

Assume i have javascript object called "call" and i have stored some values in it and i want to access the same object "call" not values. This type of approach is it possible?

If yes plese explain with simple example.

I know there are several ways we can send the object properties values from one page to another page by using post url, header, cookies so on but my requirment to access the whole object instanse form one page to another page.

Anything in this regard highly appreciated. Thanks in advance.

2 Answers 2

4

Just in addition to @gulshanm01's answer to store and retrieve an object you can use JSON.parse() and JSON.stringify() to parse the stored object.

E.g:

var obj = {
    fruit: "banana",
    fruit2: "apple",
    fruit3: "orange"
};
//Store
localStorage.setItem("obj", JSON.stringify(obj));
//Then retrieve
var localObj = JSON.parse(localStorage.getItem(obj));
alert(localObj.fruit);
Sign up to request clarification or add additional context in comments.

1 Comment

it will looks better if you put quotes around 'obj' and it will work also then otherwise it will say obj not declared :)
2

you can use localStorage.setItem(key,value) and fetch the value on another page using localStorage.getItem(key)

1 Comment

Thanks for quick response.. can i store object in value field and get the object by using localStorage.getItem(key)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.