Answer the question
In order to leave comments, you need to log in
Why is a string returned instead of an array?
Hello, why is a string returned and not an array?
var cart = [
{id: '1', name: 'gel1', photo: '1.png', price: '1.50'},
{id: '2', name: 'gel2', photo: '2.png', price: '2.50'},
];
$.cookie('cart', JSON.stringify(cart));
let cart = $.cookie('cart');
if (cart != undefined) {
for (var i = 0; i < cart.length; i++) {
alert(cart[i]);
}
}
var cart = JSON.parse($.cookie('name'));
Answer the question
In order to leave comments, you need to log in
Maybe because you yourself turn the array into a string with this call?JSON.stringify(cart)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question