当前位置:网站首页>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'}
边栏推荐
- TortoiseSVN使用情形、安装与使用
- 49. Grouping of alphabetic ectopic words: give you a string array, please combine the alphabetic ectopic words together. You can return a list of results in any order. An alphabetic ectopic word is a
- These 18 websites can make your page background cool
- Assembly language - Beginner's introduction
- Integer = = the comparison will unpack automatically. This variable cannot be assigned empty
- Jetpack Compose入门到精通
- Zhubo Huangyu: it's really bad not to understand these gold frying skills
- jasypt配置文件加密|快速入门|实战
- Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error
- ETCD数据库源码分析——rawnode简单封装
猜你喜欢
STM32 reverse entry
redis6事务和锁机制
Zibll theme external chain redirection go page beautification tutorial
[public class preview]: basis and practice of video quality evaluation
How to deal with the Yellow Icon during the installation of wampserver
::ffff:192.168.31.101 是一个什么地址?
Catch all asynchronous artifact completable future
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
NFT value and white paper acquisition
Solve the problem of invalid uni app configuration page and tabbar
随机推荐
Laravel框架运行报错:No application encryption key has been specified
龙芯派2代烧写PMON和重装系统
Requests + BS4 crawl Douban top250 movie information
Redis6 data type and operation summary
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
matlab学习2022.7.4
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
Wechat app payment callback processing method PHP logging method, notes. 2020/5/26
Hide Chinese name
蓝桥杯学习2022.7.5(上午)
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
Ordering system based on wechat applet
Etcd database source code analysis -- rawnode simple package
Summit review | baowanda - an integrated data security protection system driven by compliance and security
Idea remote debugging agent
Jetpack compose introduction to mastery
法国学者:最优传输理论下对抗攻击可解释性探讨
Idea set method annotation and class annotation
那些考研后才知道的事
Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications