Code that runs in JavaScript it not persistent. Once the program is finished, all values in memory are discarded. You need to save the value to disk or store it in a database using a server-side language.
You can export the array with:
var savedFile_JsonStringData = JSON.stringify(nameData);
and store its string contents in a file or database.
Then, to import the data, load the saved file and convert its string representation back into an array:
var nameData = JSON.parse(savedFile_JsonStringData);
Local Storage
As others have noted, a temporary storage method may work if you don't need the data to hang around for too long.
Window.sessionStorage offers the following:
The sessionStorage
property allows you to access a session Storage object. sessionStorage
is similar to localStorage, the only difference is while data stored in localStorage
has no expiration set, data stored in sessionStorage
gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated.
Minimum browser version support
Feature | Chrome | Firefox | IE | Opera | Safari
---------------+--------+---------+----+-------+-------
localStorage | 4 | 3.5 | 8 | 10.50 | 4
sessionStorage | 5 | 2 | 8 | 10.50 | 4
Example
// Save data to sessionStorage
sessionStorage.setItem('myKey', JSON.stringify(nameData));
// Get saved data from sessionStorage
var nameData = JSON.parse(sessionStorage.getItem('myKey'));