当前位置:网站首页>js對JSON數組的增删改查
js對JSON數組的增删改查
2022-07-06 23:14:00 【~疆】
目錄
查詢記錄。根據username查詢記錄
const users = [
{ username: "張三", password: 333 },
{ username: "李四", password: 444 },
{ username: "王五", password: 555 },
];
//查詢記錄。根據username查詢記錄
let data = users.filter((item) => item.username == "張三");
console.log("根據username查詢出的記錄:", data);
删除記錄。根據username删除記錄
const users = [
{ username: "張三", password: 333 },
{ username: "李四", password: 444 },
{ username: "王五", password: 555 },
];
//删除記錄。根據username删除記錄
let data = users.filter((item) => item.username == "張三");
console.log("根據username查詢出的記錄:", data);
let index = users.indexOf(data[0]);
console.log("索引index:", index);
index !== -1 && users.splice(index, 1);
console.log("删除一條記錄後的users:", users);
修改記錄。根據username修改password
const users = [
{ username: "張三", password: 333 },
{ username: "李四", password: 444 },
{ username: "王五", password: 555 },
];
//修改記錄。根據username修改password
let data = users.filter((item) => item.username == "張三");
console.log("根據username查詢出的記錄:", data);
data[0].password = 3333;
console.log("修改一條記錄後的users:", users);
新增記錄。
const users = [
{ username: "張三", password: 333 },
{ username: "李四", password: 444 },
{ username: "王五", password: 555 },
];
//新增記錄。
users.push({ username: "趙六", password: 666 });
console.log("新增一條記錄後的users:", users);
边栏推荐
- Efficient ETL Testing
- Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
- CRMEB商城系统如何助力营销?
- docker mysql5.7如何设置不区分大小写
- How to achieve text animation effect
- [launched in the whole network] redis series 3: high availability of master-slave architecture
- Mysql 身份认证绕过漏洞(CVE-2012-2122)
- Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
- Enterprises do not want to replace the old system that has been used for ten years
- On file uploading of network security
猜你喜欢
Cocoscreator+typescripts write an object pool by themselves
为了交通安全,可以做些什么?
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
Motion capture for snake motion analysis and snake robot development
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
(shuttle) navigation return interception: willpopscope
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
Bipartite graph determination
Efficient ETL Testing
随机推荐
Isomorphism + cross end, knowing applet +kbone+finclip is enough!
DockerMySQL无法被宿主机访问的问题解决
docker中mysql开启日志的实现步骤
【全网首发】Redis系列3:高可用之主从架构的
云原生(三十二) | Kubernetes篇之平台存储系统介绍
Bipartite graph determination
同构+跨端,懂得小程序+kbone+finclip就够了!
The statement that allows full table scanning does not seem to take effect set odps sql. allow. fullscan=true; I
C three ways to realize socket data reception
CRMEB商城系统如何助力营销?
How does crmeb mall system help marketing?
华为云GaussDB(for Redis)揭秘第21期:使用高斯Redis实现二级索引
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Cover fake big empty talk in robot material sorting
Children's pajamas (Australia) as/nzs 1249:2014 handling process
同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
BasicVSR_ Plusplus master test videos and pictures
Windows auzre background operation interface of Microsoft's cloud computing products
Introduction to network basics