Home » Javascript » How to unserialize an array in Javascript

How to unserialize an array in Javascript

Posted by: admin August 19, 2018 Leave a comment

Questions:

I have arrays stored in files which have been serialized in php so that I don’t have to explode/implode every time I use the data.
Is there a way by which i can unserialize and add a dimension to it in JS ?

the php equivalent would look like

$key = $_POST['num'];
$array = unserialize(file_get_contents("file.data");
$array[$key][0] = "marked";
file_put_contents(serialize($array);  

the array $key[0] does not yet exist but i don’t know if it will affect the rest of the the code

Answers: