当前位置:网站首页>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);
边栏推荐
- (shuttle) navigation return interception: willpopscope
- On the problems of born charge and non analytical correction in phonon and heat transport calculations
- 实现多彩线条摆出心形
- B站大佬用我的世界搞出卷積神經網絡,LeCun轉發!爆肝6個月,播放破百萬
- Project duplicate template
- 浅谈网络安全之文件上传
- [launched in the whole network] redis series 3: high availability of master-slave architecture
- 同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
- mysql拆分字符串作为查询条件的示例代码
猜你喜欢
Motion capture for snake motion analysis and snake robot development
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型
NFTScan 开发者平台推出 Pro API 商业化服务
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Cocoscreator+typescripts write an object pool by themselves
机器人材料整理中的套-假-大-空话
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
cuda 探索
MATLAB小技巧(27)灰色预测
监控界的最强王者,没有之一!
随机推荐
[compilation principle] LR (0) analyzer half done
同构+跨端,懂得小程序+kbone+finclip就够了!
How to choose the server system
Matlab tips (27) grey prediction
Cloud native technology container knowledge points
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Motion capture for snake motion analysis and snake robot development
What can be done for traffic safety?
石墨文档:4大对策解决企业文件信息安全问题
同一个作业有两个source,同一链接不同数据库账号,为何第二个链接查出来的数据库列表是第一个账号的
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
MySQL数据库之JDBC编程
Introduction to network basics
Redis persistence mechanism
Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
A few suggestions for making rust library more beautiful! Have you learned?
POJ 1258 Agri-Net
Use ECs to set up an agent