当前位置:网站首页>JS - 修改数组中对象的键名
JS - 修改数组中对象的键名
2022-07-28 10:35:00 【Jie_1997】
转换方法
/** * arr:数组 * key:新key名 * replaceKey:原始key名 **/ function replaceObjectKey(arr, key, replaceKey) { let newArr = []; arr.forEach((item, index) => { for (var i = 0; i < key.length; i++) { item[key] = item[replaceKey]; } // 删除原始key名 delete item[replaceKey]; newArr.push(item); }); return newArr; }使用方法:
let arr = [ { id: 1, address: "南京", }, { id: 2, address: "合肥", }, { id: 3, address: "上海", }, ]; let newArr = replaceObjectKey(arr, "label", "address"); console.log(newArr);打印结果

边栏推荐
- float浮动初步理解
- Configuring raspberry pie, process and problems encountered
- 低代码十问:一文讲透关于低代码的一切!
- 蓝桥杯嵌入式-HAL库-USART_RX
- 2021-03-24
- samba服务器配置
- Network file system service (NFS)
- PyQt5快速开发与实战 4.12 日历与时间
- Purchase, sale and inventory software suitable for small and medium-sized enterprises to solve five major problems
- Andorid development III (intent)
猜你喜欢

Learn these analysis methods and models, and no longer have no ideas when encountering problems

19. Delete the penultimate node of the linked list

Table data processing software, what else besides excel?

Attention attention mechanism flow chart

Inventory: 6 books teach you the necessary skills for career promotion

Do data analysis, do you still not understand RFM analysis method (model)?

低代码十问:一文讲透关于低代码的一切!

21. Merge two ordered linked lists

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

Sword finger offer 35. replication of complex linked list
随机推荐
Causes and solutions of invalid ROM table
GKCylindersNoiseSource
蓝桥杯嵌入式-HAL库-LCD
Make a virtual human with zego avatar | virtual anchor live broadcast solution
学会这些分析方法及模型,遇到问题不再没思路
cortex-M4与cortex-A7内核启动流程分析
Redis-day01 common sense supplement and redis introduction
21. Merge two ordered linked lists
Pyqt5 rapid development and practice 4.13 menu bar, toolbar and status bar and 4.14 qprinter
Crm+ zero code: easily realize enterprise informatization
PyQt5快速开发与实战 4.13 菜单栏、工具栏与状态栏 and 4.14 QPrinter
GKNoiseMap
GKARC4RandomSource
使用statement对象执行DDL语句创建表
Apb2 and apb1 in stm32
GKSpheresNoiseSource
Problems needing attention when VC links static libraries
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
MySQL Architecture Principle
Install MySQL based on docker