S
S
slowkazak2015-09-20 11:13:47
JavaScript
slowkazak, 2015-09-20 11:13:47

What could be the problem with javascript array?

good afternoon!
can someone explain to me why this line works

items=[{"cid":"345498","q":1,"tq":3,"im":"5802177","imf":"444444444","ie":"true","iprt":11393,"ipr":11393},
{"cid":"345476","q":1,"tq":2,"im":"9905000","imf":"33333","ie":"true","iprt":14554,"ipr":14554},
{"cid":"345472","q":1,"tq":10,"im":"VORK5000","imf":"2222222222","ie":"true","iprt":15530,"ipr":15530},
{"cid":"345457","q":1,"tq":1,"im":"2742101","imf":"11111111111","ie":"true","iprt":24163,"ipr":24163}]

But this one doesn't work: Provided that in $.cookie('arr'); stored the same
items=$.cookie('arr');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-09-20
@slowkazak

Only simple types can be stored in cookies.
Convert the array to JSON:

//Запись
items = [
   {"cid":"345498", "q":1, "tq":3, "im":"5802177", "imf":"444444444", "ie":"true", "iprt":11393, "ipr":11393},
   {"cid":"345476", "q":1, "tq":2," im":"9905000", "imf":"33333", "ie":"true", "iprt":14554, "ipr":14554}
];
$.cookie("arr", JSON.stringify(items));

//Чтение
var arr = JSON.parse($.cookie("arr"));
alert(arr[0].cid);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question