passing an array from EJS to Javascript

前端 未结 5 890
隐瞒了意图╮
隐瞒了意图╮ 2021-01-20 23:48

I am trying to passe an array from ejs to JavaScript. I can get to the values inside ejs but not from JavaScript. all the time i get undefined because the contents of the variab

5条回答
  •  鱼传尺愫
    2021-01-21 00:18

    I process like that to pass array from express to an EJS page: in the node.js code :

    .post('/action', function(req, res) {
            var arr = ["premier", "second", "troisième", "quatrieme", "cinquieme"];
            res.render('page.ejs', {arr: arr}); 
    });
    

    And in page.ejs :

    <% for(var i = 0 ; i < arr.length ; i++) { %>
           
                <%= arr[i] %>
           
    <% } %>
    

提交回复
热议问题