惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Visual Studio Blog
宝玉的分享
宝玉的分享
IT之家
IT之家
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
I
InfoQ
B
Blog RSS Feed
T
Threatpost
博客园_首页
M
MIT News - Artificial intelligence
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Know Your Adversary
Know Your Adversary
U
Unit 42
Engineering at Meta
Engineering at Meta
C
Cyber Attacks, Cyber Crime and Cyber Security
月光博客
月光博客
Scott Helme
Scott Helme
T
Tor Project blog
有赞技术团队
有赞技术团队
AWS News Blog
AWS News Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
S
Schneier on Security
Vercel News
Vercel News
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
L
LangChain Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
雷峰网
雷峰网
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
S
Security Affairs
A
About on SuperTechFans
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
大猫的无限游戏
大猫的无限游戏
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
罗磊的独立博客

博客园 - smile轉角

【js】ES5,ES6继承是如何实现的 【js】setTimeout、Promise、Async/Await 的区别 【面试题】思维逻辑方面 【js】js内置对象Error(错误机制) 【TS】学习笔记 【js】CommonJS、AMD、CMD三种规范 【其他】查看Animate.css官网动画没有效果 【vue3】父子组件通信之 vue3 defineProps,defineEmits ,defineExpose 【js】JS严格模式有什么特点 【css】使用弹性盒子布局时,省略号问题 【vue】 Failed to load resource: the server responded with a status of 404 (Not Found) 【第三方】富文本调研 【js】元素是否在可视区范围内 【vue3】资料 【css】展示背景图片的底部部分 【html】 svg 【html5】html5中input 标签 type值为range时,修改其默认css 【js】forEach,for...in,for...of 区别 【js】map,reduce,filter的区别
【js】json的相关操作
smile轉角 · 2022-10-27 · via 博客园 - smile轉角

1、将json 数据和数组融合
demo

    <script>
        var json = {
            all: 10,
            un: 3,
            comp: 2,
            inc: 5

        }
        var arr = [
            {
                text: '全部',
                type: "",
            },
            { 
                text: '未参加', 
                type: "0", 
            },
            { 
                text: '未完成', 
                type: "1", 
            },
            { 
                text: '已完成', 
                type: "2", 
            },
        ];

        // 目标结果:
        arr = [
            { 
                text: '全部',
                type: "", 
                counts: 10
            },
            {
                text: '未参加', 
                type: "0", 
                counts: 3
            },
            { 
                text: '未完成', 
                type:  "1", 
                counts: 5
            },
            { 
                text: '已完成', 
                type: "2", 
                counts: 2
            },
        ];
        //实现  为arr 增加key值   
        var arr = [
            { 
                text: '全部', 
                type: "", 
                key: 'all' 
            },
            { 
                text: '未参加', 
                type: "0", 
                key: 'un' 
            },
            { 
                text: '未完成', 
                type: "1", 
                key: 'inc' 
            },
            { 
                text: '已完成', 
                type: "2", 
                key: 'comp' 
            }, 
        ];
        arr.forEach(item => {
            item.counts = json[item.key]
        });
        console.log(arr);
    </script>

2、将json 连接为 a=1&b=2

思路:先将json 变为数组 ['a=1','b=2']

然后再将数组变成字符串

var json2 = {
    a : 1,
    n : 5
}
let reloadPathHelper = (json) =>{
    return Object.keys(json).map(key => key + '=' + json[key]).join('&');
};
console.log(reloadPathHelper(json2));

方法二

var arr = [];
for(var key in json2){
    arr.push(key + '=' + json2[key]);
}
console.log(arr.join('&'));