当前位置:网站首页>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);
边栏推荐
- Matlab tips (27) grey prediction
- 借助这个宝藏神器,我成为全栈了
- 企业不想换掉用了十年的老系统
- three. JS gorgeous bubble effect
- Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
- Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
- 「小程序容器技术」,是噱头还是新风口?
- ACL 2022 | 序列标注的小样本NER:融合标签语义的双塔BERT模型
- Let's see through the network i/o model from beginning to end
- MySQL数据库之JDBC编程
猜你喜欢
Mysql 身份认证绕过漏洞(CVE-2012-2122)
Gpt-3 is a peer review online when it has been submitted for its own research
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
How to choose indoor LED display? These five considerations must be taken into account
(1) Chang'an chain learning notes - start Chang'an chain
Cloud native technology container knowledge points
Isomorphism + cross end, knowing applet +kbone+finclip is enough!
Traversal of a tree in first order, middle order, and then order
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
Dockermysql modifies the root account password and grants permissions
随机推荐
石墨文档:4大对策解决企业文件信息安全问题
Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
Matlab tips (27) grey prediction
案例推荐丨安擎携手伙伴,保障“智慧法院”更加高效
AcWing 4300. Two operations (minimum number of BFS searches)
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
Custom swap function
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
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
Cloud native (32) | kubernetes introduction to platform storage system
Enterprises do not want to replace the old system that has been used for ten years
None of the strongest kings in the monitoring industry!
(DART) usage supplement
Introduction to network basics
Two week selection of tdengine community issues | phase II
(shuttle) navigation return interception: willpopscope
Traversal of a tree in first order, middle order, and then order
动作捕捉用于蛇运动分析及蛇形机器人开发
BasicVSR_ Plusplus master test videos and pictures
Bipartite graph determination