当前位置:网站首页>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'}
边栏推荐
- Attack and defense world crypto WP
- Record in-depth learning - some bug handling
- Shuttle INKWELL & ink components
- Flutter 3.0更新后如何应用到小程序开发中
- Multi person cooperation project to see how many lines of code each person has written
- Solution to the prompt of could not close zip file during phpword use
- Ueditor + PHP enables Alibaba cloud OSS upload
- Clock cycle
- RK3566添加LED
- Kafaka log collection
猜你喜欢
MMSeg——Mutli-view时序数据检查与可视化
Primary code audit [no dolls (modification)] assessment
Solve the problem of invalid uni app configuration page and tabbar
Catch all asynchronous artifact completable future
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
Intranet penetration tool NetApp
How to deal with the Yellow Icon during the installation of wampserver
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
Mmseg - Mutli view time series data inspection and visualization
随机推荐
leetcode 10. Regular expression matching regular expression matching (difficult)
The development of speech recognition app with uni app is simple and fast.
Wechat app payment callback processing method PHP logging method, notes. 2020/5/26
Win10——轻量级小工具
Liar report query collection network PHP source code
龙芯派2代烧写PMON和重装系统
今年上半年,通信行业发生了哪些事?
What happened to the communication industry in the first half of this year?
When there are too many input boxes such as input transmitted at one time in the form, the post data is intercepted
53. 最大子数组和:给你一个整数数组 nums ,请你找出一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和。
stm32逆向入门
运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
49. 字母异位词分组:给你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的字母得到的一个新单词,所有源单词中的字母通常恰好只用一次。
kafaka 日志收集
Aspx simple user login
不知道这4种缓存模式,敢说懂缓存吗?
Zibll theme external chain redirection go page beautification tutorial
【MySQL 使用秘籍】一網打盡 MySQL 時間和日期類型與相關操作函數(三)
Simple PHP paging implementation
Can and can FD