1

I have a JSON array in localstorage. I want to retrieve this array, and display the values. The storage key is _myobject, and the value is

[{"64508":"12:12:2"},{"5292":"12:17:34"}]

What I want is to know how I can use JavaScript/jQuery to display/print the values in the following format:

Number: 64508 - Time:  12:12:2
Number: 5292 - Time: 12:17:34

Could somebody please direct me on how I could do this?

1 Answer 1

4

You can use an Array.map to convert from your array into the string. Try something like this:

var obj = JSON.parse(localStorage.getItem("_myobject"));
obj.map(function(item) { 
     // (really just the first key)
     for (var key in item) 
         return "Number: " + key + " - Time: " + item[key]; 
}).join(" ");

(Fiddle)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. This worked perfectly after I worked with the fiddle link. I really appreciate your time.

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.