当前位置:网站首页>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'}
边栏推荐
- ::ffff:192.168.31.101 是一个什么地址?
- PHP character capture notes 2020-09-14
- Parsing XML using Dom4j
- TortoiseSVN使用情形、安装与使用
- ELFK部署
- What are the private addresses
- stm32逆向入门
- Those things I didn't know until I took the postgraduate entrance examination
- The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
- The real king of caching, Google guava is just a brother
猜你喜欢
::ffff:192.168.31.101 是一个什么地址?
法国学者:最优传输理论下对抗攻击可解释性探讨
Jetpack compose introduction to mastery
Laravel框架运行报错:No application encryption key has been specified
Network security - Novice introduction
Idea设置方法注释和类注释
我为什么支持 BAT 拆掉「AI 研究院」
Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
锚点导航小demo
:: ffff:192.168.31.101 what address is it?
随机推荐
真正的缓存之王,Google Guava 只是弟弟
ELK 企业级日志分析系统
[machine learning notes] how to solve over fitting and under fitting
js 从一个数组对象中取key 和value组成一个新的对象
Requests + BS4 crawl Douban top250 movie information
zabbix 监控
Interviewer soul torture: why does the code specification require SQL statements not to have too many joins?
嵌入式软件架构设计-消息交互
PostgreSQL Usage Summary (PIT)
matlab学习2022.7.4
Embedded software architecture design - message interaction
Idea set method annotation and class annotation
锚点导航小demo
How to deal with the Yellow Icon during the installation of wampserver
我为什么支持 BAT 拆掉「AI 研究院」
法国学者:最优传输理论下对抗攻击可解释性探讨
Win10 - lightweight gadget
【云资源】云资源安全管理用什么软件好?为什么?
uplad_ Labs first three levels
Pancake Bulldog robot V2 (code optimized)