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

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
D
Docker
Vercel News
Vercel News
IT之家
IT之家
Recent Announcements
Recent Announcements
Last Week in AI
Last Week in AI
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
腾讯CDC
Google DeepMind News
Google DeepMind News
I
InfoQ
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
博客园 - Franky
The Cloudflare Blog
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
T
Tenable Blog
P
Proofpoint News Feed
Recorded Future
Recorded Future
Security Latest
Security Latest
H
Hackread – Cybersecurity News, Data Breaches, AI and More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 聂微东
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google Online Security Blog
Google Online Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Simon Willison's Weblog
Simon Willison's Weblog
The Last Watchdog
The Last Watchdog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
TaoSecurity Blog
TaoSecurity Blog
U
Unit 42
The Hacker News
The Hacker News
Martin Fowler
Martin Fowler
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
F
Full Disclosure
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
Project Zero
Project Zero

博客园 - 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('&'));