当前位置:网站首页>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);
边栏推荐
- 欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- Mysql 身份认证绕过漏洞(CVE-2012-2122)
- Windows auzre background operation interface of Microsoft's cloud computing products
- 基于PaddlePaddle平台(EasyDL)设计的人脸识别课堂考勤系统
- 请问async i/o可以由udf算子实现然后用sql api调用吗?目前好像只看到Datastre
- MySQL authentication bypass vulnerability (cve-2012-2122)
- Use mitmproxy to cache 360 degree panoramic web pages offline
- UE4 blueprint learning chapter (IV) -- process control forloop and whileloop
- B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
猜你喜欢
How to choose indoor LED display? These five considerations must be taken into account
Rust knowledge mind map XMIND
Traversal of a tree in first order, middle order, and then order
#DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)
Custom swap function
Les entreprises ne veulent pas remplacer un système vieux de dix ans
MySQL实现字段分割一行转多行的示例代码
云原生(三十二) | Kubernetes篇之平台存储系统介绍
[compilation principle] LR (0) analyzer half done
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
随机推荐
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
第十九章 使用工作队列管理器(二)
OpenSSL: a full-featured toolkit for TLS and SSL protocols, and a general encryption library
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
How to choose indoor LED display? These five considerations must be taken into account
MySQL实现字段分割一行转多行的示例代码
Graphite document: four countermeasures to solve the problem of enterprise document information security
室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
On the problems of born charge and non analytical correction in phonon and heat transport calculations
The application of machine learning in software testing
Devsecops software R & D security practice - release
Chapter 19 using work queue manager (2)
C three ways to realize socket data reception
How does crmeb mall system help marketing?
BasicVSR_ Plusplus master test videos and pictures
What can be done for traffic safety?
企业不想换掉用了十年的老系统
Efficient ETL Testing
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
dockermysql修改root账号密码并赋予权限