json, string object conversion related (express, ejs template)

Asked 1 years ago, Updated 1 years ago, 91 views

Node.js + express is under development.

The data type I want to use in javascript is

var word_array = [
      {text: "Lo", age: 15},
      {text: "Ip", age: 9},
      {text: "Do", age: 6},
      {text: "Si", age: 7},
      {text: "Am", age: 5}
    ];

This is.

Therefore, the result variable data selected by the server stage are as follows

var word_array = new Array();

for (var i=0; i<result.length; i++) {

    word_array.push(
        {
            text: result[i].name,
            age: result[i].age
        }
    );
}

I put it in and passed it to ejs and sprayed it on the console.

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

It comes out together...

How to store data on type I want?

json string ejs express node.js

2022-09-22 10:33

1 Answers

Check the output by changing it to a string.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

console.log(JSON.stringify(tmp));


2022-09-22 10:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.