0

I am trying to pass an array of arrays from routes to view page. My data that I am trying to pass is :

[
    [10, 10],
    [20, 50],
    [30, 120],
    [40, 80],
    [50, 90],
    [60, 50],
    [70, 70],
    [80, 90],
    [90, 150],
    [100, 50],
    [110, 40],
    [120, 70],
    [130, 20],
    [140, 40],
    [200, 30]
]

I am getting it in below format:

["10,10,20,50,30,120,40,80,50,90,60,50,70,70,80,90,90,150,100,50,110,40,120,70,130,20,140,40,200,30"]

but I need it in the same format I am sending. My index.js(routes file) is:

router.get('/', function(req, res, next) {
var dataset = [
    [10, 10],
    [20, 50],
    [30, 120],
    [40, 80],
    [50, 90],
    [60, 50],
    [70, 70],
    [80, 90],
    [90, 150],
    [100, 50],
    [110, 40],
    [120, 70],
    [130, 20],
    [140, 40],
    [200, 30]
];
console.log(dataset);
res.render('index',{"data" : [dataset]});
});

module.exports = router;

and in my view file, I am trying to get it like:

<div class="hold_data" data-info={{data}}></div>

Please suggest if anyone knows how this can be achieved. Thanks in advance :)

8
  • Try adding it as a value to a key. That should work. Also, some code would be better to help you debug. Share your code. Commented Nov 29, 2015 at 4:09
  • @Bazinga777: added more info in the question. Please see now Commented Nov 29, 2015 at 4:27
  • res.render('index',{"data" : dataset}); use this one .. see if this helps.. Commented Nov 29, 2015 at 5:23
  • @Chandan : Initially used this one but same result Commented Nov 29, 2015 at 6:07
  • 1
    can you try this one - res.render('index',{"data" : JSON.stringify(dataset)}); also provide where/how are you actually getting this data from server...? Commented Nov 29, 2015 at 6:08

1 Answer 1

2

Try JSON.stringify as below -

 res.render('index',{"data" : JSON.stringify(dataset)});

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.