当前位置:网站首页>js对JSON数组的增删改查
js对JSON数组的增删改查
2022-07-06 15:41: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);边栏推荐
- [untitled]
- Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
- With the help of this treasure artifact, I became the whole stack
- OpenSSL: a full-featured toolkit for TLS and SSL protocols, and a general encryption library
- 让我们,从头到尾,通透网络I/O模型
- Traversal of a tree in first order, middle order, and then order
- 浅谈网络安全之文件上传
- Redis 持久化机制
- DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
- 基于PaddlePaddle平台(EasyDL)设计的人脸识别课堂考勤系统
猜你喜欢

MySQL数据库之JDBC编程

Mysql 身份认证绕过漏洞(CVE-2012-2122)

MATLAB小技巧(27)灰色预测

使用MitmProxy离线缓存360度全景网页

Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)

Efficient ETL Testing

Les entreprises ne veulent pas remplacer un système vieux de dix ans

室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内

Cloud native (32) | kubernetes introduction to platform storage system

UE4 blueprint learning chapter (IV) -- process control forloop and whileloop
随机推荐
On file uploading of network security
On the problems of born charge and non analytical correction in phonon and heat transport calculations
spark调优(二):UDF减少JOIN和判断
Why are some people still poor and living at the bottom of society even though they have been working hard?
[launched in the whole network] redis series 3: high availability of master-slave architecture
企業不想換掉用了十年的老系統
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon
Two week selection of tdengine community issues | phase II
Cloud native technology container knowledge points
Introduction to network basics
「小程序容器技术」,是噱头还是新风口?
Redis persistence mechanism
View
CRMEB商城系统如何助力营销?
Method of canceling automatic watermarking of uploaded pictures by CSDN
Automatically update selenium driver chromedriver
Use mitmproxy to cache 360 degree panoramic web pages offline
Dockermysql modifies the root account password and grants permissions
Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
TDengine 社区问题双周精选 | 第二期