I used jQuery to create a cookie album_like
that store an array of id
, I would like to add/push new value to this array when some condition met, below is my code
if (typeof $.cookie('album_like') == 'undefined') {
$.cookie('album_like', [data.album_id], { expires: 365, path: '/' });
} else {
var arr = [$.cookie('album_like')];
if (!($.inArray(data.album_id, arr) > 0)) {
arr.push(data.album_id);
$.cookie('album_like', arr);
}
}
I found that the array become ["1, 2, 3, 4, 5"]
when I use firebug to check the value, so the code !($.inArray(data.album_id, arr) > 0)
not work, I think the array should be [1, 2, 3, 4, 5]
.
Anyone could give some advice on my code?
Thanks