当前位置:网站首页>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'}
边栏推荐
- 这18个网站能让你的页面背景炫酷起来
- Wonderful express | Tencent cloud database June issue
- jenkins安装
- How to deal with the Yellow Icon during the installation of wampserver
- 记录一下在深度学习-一些bug处理
- Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
- About the problem and solution of 403 error in wampserver
- NFT value and white paper acquisition
- 那些考研后才知道的事
- Assembly language - Beginner's introduction
猜你喜欢
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
The real king of caching, Google guava is just a brother
Huawei push service content, read notes
[deep learning paper notes] hnf-netv2 for segmentation of brain tumors using multimodal MR imaging
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
一网打尽异步神器CompletableFuture
Redis6 transaction and locking mechanism
Laravel框架运行报错:No application encryption key has been specified
When using Tencent cloud for the first time, you can only use webshell connection instead of SSH connection.
随机推荐
Laravel框架运行报错:No application encryption key has been specified
With 4 years of working experience, you can't tell five ways of communication between multithreads. Dare you believe it?
Win10——轻量级小工具
redis6事务和锁机制
搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2
Primary code audit [no dolls (modification)] assessment
PHP character capture notes 2020-09-14
Backup and restore of Android local SQLite database
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
Ueditor + PHP enables Alibaba cloud OSS upload
Simple PHP paging implementation
Jenkins installation
JS to determine whether an element exists in the array (four methods)
PHP basic syntax
Log4j utilization correlation
C object storage
今年上半年,通信行业发生了哪些事?
Datapipeline was selected into the 2022 digital intelligence atlas and database development report of China Academy of communications and communications
Jetpack Compose入门到精通
【MySQL 使用秘籍】一網打盡 MySQL 時間和日期類型與相關操作函數(三)