当前位置:网站首页>js 从一个数组对象中取key 和value组成一个新的对象
js 从一个数组对象中取key 和value组成一个新的对象
2022-07-05 13:47:00 【蓝胖子的多啦A梦】
从一个数组对象中取key 和value组成一个新的对象
const type = [
{
amount: '', size: '4013' },
{
amount: '1', size: '1613' },
{
amount: '5', size: '2007' },
{
amount: '9', size: '3613' },
{
amount: '', size: '2413' },
{
amount: '10', size: '1213' },
{
amount: '', size: '3213' },
{
amount: '11', size: '2013' },
{
amount: '', size: '0807' },
{
amount: '', size: '2807' },
{
amount: '6', size: '1607' }
]
let newArr={
};
type .map(itm=>{
newArr[itm.size] = itm.amount
})
console.log('1',newArr)
{
1213: '10', 1607: '6', 1613: '1', 2007: '5', 2013: '11', 2413: '', 2807: '', 3213: '', 3613: '9', 4013: '', 0807: ''}
tips:去掉里面的空值
let newArr={
};
type .map(itm=>{
if (itm.amount) {
newArr[itm.size] = itm.amount
}
})
console.log('1',newArr)
{
1213: '10', 1607: '6', 1613: '1', 2007: '5', 2013: '11', 3613: '9'}
边栏推荐
- What about data leakage? " Watson k'7 moves to eliminate security threats
- restTemplate详解
- Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
- ::ffff:192.168.31.101 是一个什么地址?
- ETCD数据库源码分析——rawnode简单封装
- 【云资源】云资源安全管理用什么软件好?为什么?
- 49. Grouping of alphabetic ectopic words: give you a string array, please combine the alphabetic ectopic words together. You can return a list of results in any order. An alphabetic ectopic word is a
- French scholars: the explicability of counter attack under optimal transmission theory
- Prefix, infix, suffix expression "recommended collection"
- 多人合作项目查看每个人写了多少行代码
猜你喜欢

Idea设置方法注释和类注释

Could not set property ‘id‘ of ‘class XX‘ with value ‘XX‘ argument type mismatch 解决办法

Attack and defense world web WP

Zibll theme external chain redirection go page beautification tutorial

Intranet penetration tool NetApp

Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?

Binder communication process and servicemanager creation process
![[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation](/img/70/6de0346df8527af6c88db1ff89947b.png)
[notes of in-depth study paper]transbtsv2: wider instead of deep transformer for medical image segmentation

STM32 reverse entry

Solve the problem of invalid uni app configuration page and tabbar
随机推荐
uplad_ Labs first three levels
What about data leakage? " Watson k'7 moves to eliminate security threats
Shuttle INKWELL & ink components
What happened to the communication industry in the first half of this year?
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
Redis6 transaction and locking mechanism
记录一下在深度学习-一些bug处理
53. Maximum subarray sum: give you an integer array num, please find a continuous subarray with the maximum sum (the subarray contains at least one element) and return its maximum sum.
Wechat app payment callback processing method PHP logging method, notes. 2020/5/26
FPGA learning notes: vivado 2019.1 add IP MicroBlaze
Prefix, infix, suffix expression "recommended collection"
Summary and arrangement of JPA specifications
::ffff:192.168.31.101 是一个什么地址?
Could not set property 'ID' of 'class xx' with value 'XX' argument type mismatch solution
Assembly language - Beginner's introduction
4年工作经验,多线程间的5种通信方式都说不出来,你敢信?
Laravel generate entity
【MySQL 使用秘籍】一网打尽 MySQL 时间和日期类型与相关操作函数(三)
法国学者:最优传输理论下对抗攻击可解释性探讨
49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。