You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从查询返回的Client对象数组中提取所有full_name字段组成新数组

实现思路

你拿到的查询结果是标准的对象数组结构,要提取每个对象的指定字段组成新数组,直接用数组自带的map遍历方法就能实现,这是最简洁高效的方案,不需要额外复杂处理。

代码示例

// 此处clientList为你每次关键词查询后得到的Client列表返回值
const clientList = [
  {
    id: 1,
    full_name: "James Marius Bolord",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  },
  {
    id: 23,
    full_name: "Carl Barard",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  },
  {
    id: 9,
    full_name: "Tony Falape",
    email: "mariusjames32@gmail.com",
    phone: "9832910293",
    dob: "1981-05-05",
    location: "REXDALE",
    user_id: 1
  }
]

// 核心提取逻辑,每次查询后调用即可生成对应full_name数组
const full_name = clientList.map(client => client.full_name)

如果你想用已经掌握的Object.entries方法实现,也可以用下面的写法,适合需要动态匹配字段名的场景:

const full_name = clientList.map(client => {
  for (const [key, value] of Object.entries(client)) {
    if (key === 'full_name') return value
  }
})

运行后输出的结果完全符合要求:

["James Marius Bolord", "Carl Barard", "Tony Falape"]

内容的提问来源于stack exchange,提问作者chablis-omoba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 06:54:00