Reputation: 430
I'm using JavaScript Cookie and I set the the cookie with a value of a blank array, but when i try to read te value, the return type is not an array. What am I doing wrong and why is it wrong?
if (Cookies.get('saved_boards') == null) {
var array = new Array();
Cookies.set('saved_boards', array, {
expires: 1
});
}
var saves = Cookies.get('saved_boards'); // saves is not of array type
Upvotes: 0
Views: 36
Reputation: 430
As @nnnnnn pointed out, the array was set to a string when set as the value of a cookie, therefore parsing is needed to get the response as an array.
var saves = Cookies.getJSON('saved_boards');
This method gets and parses the response in one step.
Upvotes: 1