当前位置:网站首页>JS takes key and value from an array object to form a new object
JS takes key and value from an array object to form a new object
2022-07-05 13:50:00 【Blue fatty's Dora A Dream】
Get from an array object key and value Form a new object
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: Remove the null value inside
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'}
边栏推荐
- Zibll theme external chain redirection go page beautification tutorial
- What happened to the communication industry in the first half of this year?
- Win10 - lightweight gadget
- Programmer growth Chapter 8: do a good job of testing
- Etcd database source code analysis -- rawnode simple package
- redis6事务和锁机制
- Assembly language - Beginner's introduction
- 锚点导航小demo
- Multi person cooperation project to see how many lines of code each person has written
- 华为推送服务内容,阅读笔记
猜你喜欢

Idea设置方法注释和类注释

华为推送服务内容,阅读笔记

Idea set method annotation and class annotation

When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.

Network security - Novice introduction

深拷贝真难

TortoiseSVN使用情形、安装与使用

Elfk deployment

Ordering system based on wechat applet

redis6事务和锁机制
随机推荐
ELFK部署
Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"
链表(简单)
通讯录(链表实现)
Network security HSRP protocol
Idea set method annotation and class annotation
Laravel框架运行报错:No application encryption key has been specified
The development of speech recognition app with uni app is simple and fast.
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
redis6数据类型及操作总结
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
Godson 2nd generation burn PMON and reload system
Mmseg - Mutli view time series data inspection and visualization
Ueditor + PHP enables Alibaba cloud OSS upload
PHP generate Poster
Huawei push service content, read notes
The real king of caching, Google guava is just a brother
Requests + BS4 crawl Douban top250 movie information
Ordering system based on wechat applet
Log4j utilization correlation