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

JavaScript中如何解构对象数组?移除指定属性示例

使用解构操作移除对象数组中的指定属性

原数组:

const myArray = [
    {id:1, Fname:'Parker',Lname:'Smith',email:'demo@gmail.com',phone:"1313",adress:"TEst"},
    {id:2, Fname:'Robet',Lname:'Leng',email:'demo@gmail.com',phone:"1313",adress:"TEst"},
    {id:3, Fname:'Asia',Lname:'Smith',email:'demo@gmail.com',phone:"1313",adress:"TEst"},
];

目标数组:

const DestructuringArray = [
    {id:1, Fname:'Parker',Lname:'Smith',email:'demo@gmail.com',phone:"1313"},
    {id:2, Fname:'Robet',Lname:'Leng',email:'demo@gmail.com',phone:"1313"},
    {id:3, Fname:'Asia',Lname:'Smith',email:'demo@gmail.com',phone:"1313"},
];

解法代码

结合数组map方法与对象解构语法,可快速实现需求:

const DestructuringArray = myArray.map(({ adress, ...rest }) => rest);

说明

  • 用map遍历原数组的每个对象
  • 对单个对象解构时,将不需要的adress属性单独提取,通过...rest语法收集其余需要保留的属性
  • 返回rest对象,最终组成的新数组就是目标结构

内容的提问来源于stack exchange,提问作者testINGHUb

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 20:40:29