当前位置:网站首页>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

边栏推荐
- 蓝桥杯嵌入式-HAL库-ADC
- 低代码(aPaas)为什么最近又火了?
- RHEL 6.4 安装svn和apache
- Sword finger offer 30. stack containing min function
- Nodejs: return value of mongodb after successful insertion
- Use the statement object to execute DDL statements to create tables
- Inventory: 144 free learning websites, the most complete collection of resources in the whole network
- 蓝桥杯嵌入式-HAL库-USART_TX
- Ten questions about low code: tell everything about low code!
- 吊打面试官的问题
猜你喜欢

19. Delete the penultimate node of the linked list

蓝桥杯嵌入式-HAL库-LCD

蓝桥杯嵌入式-HAL库-USART_TX

Blue Bridge Cup embedded Hal library ADC

Crm+ zero code: easily realize enterprise informatization

GKCheckerboardNoiseSource

Purchase, sale and inventory software suitable for small and medium-sized enterprises to solve five major problems

Sword finger offer 30. stack containing min function

剑指 Offer 06. 从尾到头打印链表

学会这些分析方法及模型,遇到问题不再没思路
随机推荐
Do data analysis, do you still not understand RFM analysis method (model)?
Zero code | easily realize data warehouse modeling and build Bi Kanban
Purchase, sale and inventory software suitable for small and medium-sized enterprises to solve five major problems
剑指 Offer 06. 从尾到头打印链表
FHWY工作日进度表
1. Sum of two numbers
Inventory: 6 books teach you the necessary skills for career promotion
JSON初步理解
使用共用体union及指针测试大小端
Array related knowledge points
11_ UE4 advanced_ Change male characters to female characters and modify the animation
Nodejs: set up the express service, set up the session and realize the exit operation
网络文件系统服务(NFS)
做数据分析,你还不懂RFM分析方法(模型)?
用 ZEGO Avatar 做一个虚拟人|虚拟主播直播解决方案
Nodejs: return value of mongodb after successful insertion
Make a virtual human with zego avatar | virtual anchor live broadcast solution
吊打面试官的问题
Clo********e: project management notes
GKRandom