搜索

首页  >  问答  >  正文

获取数组对象中特定键值对的方法


records = [{id: 231, first_name: "Jack", last_name: "Aston", email: "jack55@xyz.com"}, {id: 232, first_name: "Roy", last_name: "Dillon", email: "roy@xy.com"}, {id: 233, first_name: "Jacy", last_name: "Wilson", email: "jacy@x.com"}]

fields = ['id', 'email', 'last_name']

如何从记录中仅获取“id”、“email”和“last_name”,以便数据在 JavaScript 中如下所示?

new_records = [{id: 231, email: "jack55@xyz.com", last_name: "Aston"}, {id: 232, email: "roy@xy.com", last_name: "Dillon"}, {id: 233, email: "jacy@x.com", last_name: "Wilson"}]


P粉604669414P粉604669414324 天前412

全部回复(2)我来回复

  • P粉860897943

    P粉8608979432024-01-17 09:07:28

    雷雷

    回复
    0
  • P粉057869348

    P粉0578693482024-01-17 00:07:18

    雷雷

    回复
    0
  • 取消回复