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

边栏推荐
- Fhwy workday schedule
- Why is low code (apaas) popular again recently?
- 使用共用体union及指针测试大小端
- 21. Merge two ordered linked lists
- GKSpheresNoiseSource
- 分体式测斜探头安装要点及注意事项
- Advanced C language: pointer (1)
- Advance.ai sailing guide helps enterprises sail to Indonesia and grasp half of the Southeast Asian market
- Judge whether the nixie tube is a common anode or a common cathode
- Select without the order by clause, the order of the returned results is not reliable
猜你喜欢

BC35 NB模块AT指令开发总结

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

这里有一份超实用Excel快捷键合集(常用+八大类汇总)

Pyqt5 rapid development and practice 4.12 calendar and time

Ten questions about low code: tell everything about low code!

表格数据处理软件,除了Excel还有什么?

I don't know how lucky the boy who randomly typed logs is. There must be a lot of overtime

PHP发送移动MAS短信乱码的解决方法

CTF skill tree - file upload

GKCheckerboardNoiseSource
随机推荐
GKPolygonObstacle
_ HUGE and __ IMP__ HUGE in “math.h“
Solving the optimal solution of particle swarm optimization
cortex-M4与cortex-A7内核启动流程分析
5. Implement MapReduce program on window side to complete wordcount function
ctf技能树----文件上传
keil和IAR中lib库文件的生成和使用
Select without the order by clause, the order of the returned results is not reliable
Sword finger offer 06. print linked list from end to end
Why is low code (apaas) popular again recently?
数组相关的知识点
Table data processing software, what else besides excel?
Installation points and precautions of split angle probe
I don't know how lucky the boy who randomly typed logs is. There must be a lot of overtime
Ten questions about low code: tell everything about low code!
Install GMP
platform驱动平台下,关于probe函数中,形参dev的“dev->dev.of_node;”的理解
If you don't climb mountains, you don't know the height of the sky; If you don't face deep streams, you don't know the thickness of the earth
The blogs of excellent programmers at home and abroad are all here, please check it
GKBillowNoiseSource