Local Storage Variable Array
Hi,
I have a request that returns a "results" array with applicable records from my database table. On success, I would like to store, in an array local storage variable "locations", only the _id values from each record in the response array. Unfortunately, when I use localStorage.setItem("locations", JSON.stringify(data)); it saves all values from all records from the response in the local storage variable array when I only want the _id values saved. Below is what is currently being saved in my local storage variable array:
{"results":[{"createdAt":{"$date":"2016-01-29T20:58:16.089Z"},"officeTel":"64562234","officeHours":"9AM-5PM","id":"56abd268e4b0e9b36b46c617","address":"2501 W. Kennedy Boulevard Tampa, FL 33609","updatedAt":{"$date":"2016-01-29T22:10:23.532Z"},"name":"Kennedy Family Care Center"},{"officeTel":"1513451346","id":"56abd293e4b0e9b36b46c618","address":"2106 South Lois Avenue Tampa, FL 33629","name":"Lois Family Care Center","officeHours":"9AM-5PM","createdAt":{"$date":"2016-01-29T20:58:59.660Z"},"updatedAt":{"$date":"2016-01-29T22:10:21.080Z"}},{"officeTel":"351341513","updatedAt":{"$date":"2016-01-30T14:44:58.570Z"},"servicesOffered":"Cardiology","name":"Manhattan Family Care Center","officeHours":"9AM-5PM","id":"56abd2bfe4b0e9b36b46c619","_createdAt":{"$date":"2016-01-29T20:59:43.213Z"},"address":"4212 S Manhattan Avenue Tampa, FL 33611"}]}
I would like the local storage variable "locations" to look like this instead (with only _id values from above)
{ "_id": [56abd268e4b0e9b36b46c617, 56abd293e4b0e9b36b46c618, 56abd2bfe4b0e9b36b46c619] }
Is there a snippet of javascript that could help me accomplish this? Thanks!