Q:

How can I assign an array that I received from another file to another array?

Whenever I receive an array from another file all I can do is display the whole array. I cannot display a specific element or assign it to another array. I have posted some of the code below.
Below is my .js file used to run node. This is the one that sends the arrays.
var titles = [1,2,3,4];
var descriptions = [5,6,7,8];
var dates = [9,10,11,12];
var file_names = [13,14,15,16];

app.get('/home', function(req, res) {
res.render('home', { postTitles: titles, postDescriptions: descriptions, postDates: dates, postFileNames: file_names });
});

This is my home.handlebars that receives the arrays
var myTitles = {{postTitles}};
var myDescriptions = {{postDescriptions}};
var myDates = {{postDates}};
var myFileNames = {{postFileNames}};

A:

Ways to render an array in handlebars template from node backend:

When the whole array is intended to be displayed, the #each helper is used.
If only one array-element is needed to be displayed, then only that element is passed to the template (with or without the #with helper).

Example:

app.get('/home', function(req, res) {

  var myArray = [1, 2, 3, 4, 5];

  res.render('home', {

    theArray: myArray[0]

  });

});

Most often, AJAX calls are used to dynamically request data from the server into the frontend. This is the preferred way and is the basis of REST API used in all mobile and web apps.
It is also possible, to simply to stringify a server-side array and push it into the <script> tag:

Handlebars template:

...

<script type="text/javascript">

    var myArray = {{theArray}};

    // here use myArray to do whatever processing is needed

</script>

...

Server-side code:

app.get('/home', function(req, res) {

  var myArray = [1, 2, 3, 4, 5];

  var jsonString = JSON.stringify(myArray);

  res.render('home', {

    theArray: jsonString

  });

});

This is the least preferred method as far as I know. But it can the job done.

