0

At first, I send data to Jade template in Nodejs.

app.get('/', function(req, res){ var arr = new Array( {firstname: 'Gil-dong', lastname: 'Hong'}, {firstname: 'Yeong-sil', lastname: 'Jang'} ); var jsonEncode = JSON.stringify(arr); var jsonDecode = JSON.parse(jsonEncode); res.render('/show', {arr: jsonDecode, prop: 'firstname'}); }); 

Next, I want to get 'prop' for arr's property.(in Jade template)

1)

div= arr[0].prop 

2)

div= arr[0].#{prop} 

3)

var p = !{JSON.stringify(prop)} div= arr[0].p 

But nothing works. How can I send data to JSON's property?

0

1 Answer 1

1

You can use [] to access JavaScript Object property by a variable, so change your code to div= arr[0][prop]

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.