当前位置:网站首页>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'}
边栏推荐
- ELFK部署
- Zibll theme external chain redirection go page beautification tutorial
- Source code analysis of etcd database -- peer RT of inter cluster network layer client
- 53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
- Solution to the prompt of could not close zip file during phpword use
- The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
- Scientific running robot pancakeswap clip robot latest detailed tutorial
- NFT value and white paper acquisition
- Idea remote debugging agent
- Laravel框架运行报错:No application encryption key has been specified
猜你喜欢
Usage, installation and use of TortoiseSVN
Laravel framework operation error: no application encryption key has been specified
The real king of caching, Google guava is just a brother
UE源码阅读[1]---由问题入手UE中的延迟渲染
What happened to the communication industry in the first half of this year?
STM32 reverse entry
Scientific running robot pancakeswap clip robot latest detailed tutorial
Mmseg - Mutli view time series data inspection and visualization
stm32逆向入门
研究生可以不用学英语?只要考研英语或六级分数高!
随机推荐
redis6主从复制及集群
Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
嵌入式软件架构设计-消息交互
Idea set method annotation and class annotation
PHP character capture notes 2020-09-14
MySQL if else use case use
TortoiseSVN使用情形、安装与使用
Programmer growth Chapter 8: do a good job of testing
网络安全-HSRP协议
鏈錶(簡單)
Data Lake (VII): Iceberg concept and review what is a data Lake
What is information security? What is included? What is the difference with network security?
锚点导航小demo
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
Embedded software architecture design - message interaction
Scientific running robot pancakeswap clip robot latest detailed tutorial
Network security HSRP protocol
Operational research 68 | the latest impact factors in 2022 were officially released. Changes in journals in the field of rapid care
NFT value and white paper acquisition
How to divide a large 'tar' archive file into multiple files of a specific size