当前位置:网站首页>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);
边栏推荐
- None of the strongest kings in the monitoring industry!
- Some suggestions for foreign lead2022 in the second half of the year
- Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
- Automatically update selenium driver chromedriver
- Unified Focal loss: Generalising Dice and cross entropy-based losses to handle class imbalanced medi
- (1)长安链学习笔记-启动长安链
- [unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
- Dayu200 experience officer homepage AITO video & Canvas drawing dashboard (ETS)
- [compilation principle] LR (0) analyzer half done
- Spark Tuning (II): UDF reduces joins and judgments
猜你喜欢
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
(flutter2) as import old project error: inheritfromwidgetofexacttype
机器人材料整理中的套-假-大-空话
Cloud native technology container knowledge points
企业不想换掉用了十年的老系统
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
MySQL实现字段分割一行转多行的示例代码
借助这个宝藏神器,我成为全栈了
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
随机推荐
View
借助这个宝藏神器,我成为全栈了
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
Improving Multimodal Accuracy Through Modality Pre-training and Attention
Introduction to network basics
PDF批量拆分、合并、书签提取、书签写入小工具
flinksql select id ,count(*) from a group by id .
Traversal of a tree in first order, middle order, and then order
Cover fake big empty talk in robot material sorting
「小程序容器技术」,是噱头还是新风口?
基于PaddlePaddle平台(EasyDL)设计的人脸识别课堂考勤系统
欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
Cloud native technology container knowledge points
Let's see through the network i/o model from beginning to end
POJ 1094 sorting it all out
Dockermysql modifies the root account password and grants permissions
On file uploading of network security
dockermysql修改root账号密码并赋予权限
Machine test question 1
Efficient ETL Testing