当前位置:网站首页>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);
边栏推荐
- Windows auzre background operation interface of Microsoft's cloud computing products
- European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
- TDengine 社区问题双周精选 | 第二期
- Jafka source analysis processor
- Realize colorful lines and shape your heart
- asp读取oracle数据库问题
- #DAYU200体验官# 在DAYU200运行基于ArkUI-eTS的智能晾晒系统页面
- Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
- 华为云GaussDB(for Redis)揭秘第21期:使用高斯Redis实现二级索引
- dockermysql修改root账号密码并赋予权限
猜你喜欢
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
Custom swap function
asp读取oracle数据库问题
案例推荐丨安擎携手伙伴,保障“智慧法院”更加高效
同构+跨端,懂得小程序+kbone+finclip就够了!
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
(flutter2) as import old project error: inheritfromwidgetofexacttype
Introduction to network basics
ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics
Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
随机推荐
Windows auzre background operation interface of Microsoft's cloud computing products
Les entreprises ne veulent pas remplacer un système vieux de dix ans
UVa 11732 – strcmp() Anyone?
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
让我们,从头到尾,通透网络I/O模型
Introduction to network basics
Interview question: AOF rewriting mechanism, redis interview must ask!!!
DockerMySQL无法被宿主机访问的问题解决
How to choose indoor LED display? These five considerations must be taken into account
同构+跨端,懂得小程序+kbone+finclip就够了!
Pytest unit test series [v1.0.0] [pytest execute unittest test case]
DR-Net: dual-rotation network with feature map enhancement for medical image segmentation
BasicVSR_ Plusplus master test videos and pictures
实现多彩线条摆出心形
Modules that can be used by both the electron main process and the rendering process
On file uploading of network security
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
Two week selection of tdengine community issues | phase II
Pdf batch splitting, merging, bookmark extraction, bookmark writing gadget
这个『根据 op 值判断操作类型来自己组装 sql』是指在哪里实现?是指单纯用 Flink Tabl