0

I have an object (in real code there is more values inside):

req.session.params = {valueA: a, valueB: b, result: result}

I would like to pass its pairs to res.render() along the others. For now I'm doing:

res.render('mainView.ejs', {
        otherVal: x,
        valueA: a, 
        valueB: b, 
        result: result
      });

but is there a way to do that quicker? Something like:

res.render('mainView.ejs', {otherVal: x,
           {req.session.passedParams}
          });
Malvinka
  • 1,185
  • 1
  • 15
  • 36

2 Answers2

1

You can use something like below

res.render('mainView.ejs', Object.assign({otherVal: x},req.session.passedParams));

or

res.render('mainView.ejs', {{otherVal: x},...req.session.passedParams});

PS: See Surely ES6+ must have a way to merge two javascript objects together, what is it?

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
0

You could use lodash package to accomplish this easily

var _ = require('lodash');
var params = _.assign({otherVal: x}, req.session.passedParams);

console.log(params);

I hope this helps