【问题标题】:How can I change json format selected from mysql如何更改从 mysql 中选择的 json 格式
【发布时间】:2021-08-06 13:13:08
【问题描述】:

我正在使用 NodeJS 对 MySQL 数据库进行选择查询。 我怎样才能得到预期的结果?我想删除>> {title:}

我想要什么:

['test1','test2']

我的代码:

app.get('/info', function(request, response){
   var query = 'SELECT title FROM community';
   db.query(query, function(err, filelist, fields){
   if(err) console.log(err);
      console.log(filelist);
      console.log(JSON.parse(JSON.stringify(filelist));
});

我得到的结果:

[ TextRow { title: 'test1' }, TextRow { title: 'test2' } ]
[ { title: 'test1' }, { title: 'test2' } ]

【问题讨论】:

    标签: mysql node.js json


    【解决方案1】:
    const titleArr = filelist.map(item=>item.title);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-27
      • 2023-02-09
      • 1970-01-01
      • 2022-10-04
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 1970-01-01
      相关资源
      最近更新 更多