当前位置:网站首页>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);边栏推荐
- (DART) usage supplement
- Gpt-3 is a peer review online when it has been submitted for its own research
- UVa 11732 – strcmp() Anyone?
- CRMEB商城系统如何助力营销?
- Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
- Face recognition class attendance system based on paddlepaddle platform (easydl)
- View
- With the help of this treasure artifact, I became the whole stack
- 食品里的添加剂品种越多,越不安全吗?
- Docker mysql5.7 how to set case insensitive
猜你喜欢

UE4 blueprint learning chapter (IV) -- process control forloop and whileloop

让我们,从头到尾,通透网络I/O模型

ICLR 2022 | 基于对抗自注意力机制的预训练语言模型

案例推荐丨安擎携手伙伴,保障“智慧法院”更加高效

Isomorphism + cross end, knowing applet +kbone+finclip is enough!

With the help of this treasure artifact, I became the whole stack

Children's pajamas (Australia) as/nzs 1249:2014 handling process

云原生(三十二) | Kubernetes篇之平台存储系统介绍

监控界的最强王者,没有之一!

What can be done for traffic safety?
随机推荐
docker中mysql开启日志的实现步骤
Introduction to network basics
案例推荐丨安擎携手伙伴,保障“智慧法院”更加高效
面试题:AOF重写机制,redis面试必问!!!
How to choose indoor LED display? These five considerations must be taken into account
DockerMySQL无法被宿主机访问的问题解决
每人每年最高500万经费!选人不选项目,专注基础科研,科学家主导腾讯出资的「新基石」启动申报...
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
石墨文档:4大对策解决企业文件信息安全问题
Docker mysql5.7 how to set case insensitive
Gpt-3 is a peer review online when it has been submitted for its own research
BasicVSR_ Plusplus master test videos and pictures
使用MitmProxy离线缓存360度全景网页
Rust knowledge mind map XMIND
CRMEB商城系统如何助力营销?
mysql连接vscode成功了,但是报这个错
CSDN 上传图片取消自动加水印的方法
How to achieve text animation effect