当前位置:网站首页>JS - modify the key name of the object in the array
JS - modify the key name of the object in the array
2022-07-28 11:01:00 【Jie_ one thousand nine hundred and ninety-seven】
Transformation method
/** * arr: Array * key: new key name * replaceKey: original key name **/ function replaceObjectKey(arr, key, replaceKey) { let newArr = []; arr.forEach((item, index) => { for (var i = 0; i < key.length; i++) { item[key] = item[replaceKey]; } // Delete original key name delete item[replaceKey]; newArr.push(item); }); return newArr; }Usage method :
let arr = [ { id: 1, address: " nanjing ", }, { id: 2, address: " Hefei ", }, { id: 3, address: " Shanghai ", }, ]; let newArr = replaceObjectKey(arr, "label", "address"); console.log(newArr);Print the results

边栏推荐
猜你喜欢

Table data processing software, what else besides excel?

用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案

蓝桥杯嵌入式-HAL库-SYSTICK
Advanced C language: pointer (1)

Reading these six books makes learning MySQL easier

JS - 修改数组中对象的键名

11_ UE4 advanced_ Change male characters to female characters and modify the animation

GKCylindersNoiseSource

The 10th Landbridge cup embedded electronic provincial competition

做数据分析,你还不懂RFM分析方法(模型)?
随机推荐
这里有一份超实用Excel快捷键合集(常用+八大类汇总)
GKSphereObstacle
Inventory: 6 books teach you the necessary skills for career promotion
nodejs:搭建express 服务,设置session以及实现退出操作
samba学习
GKSpheresNoiseSource
MySQL Architecture Principle
蓝桥杯电子类嵌入式第十届省赛
Arduino Basics
关于结构体指针函数的返回值传递给结构体指针的理解
Samba learning
图片滑动特效
GKNoise
Problems needing attention when VC links static libraries
Judge whether the nixie tube is a common anode or a common cathode
Cortex-M内核管理全局中断的三种方式
Make a virtual human with zego avatar | virtual anchor live broadcast solution
蓝桥杯嵌入式-HAL库-USART_RX
剑指 Offer 06. 从尾到头打印链表
JDBC各个类的解释