当前位置:网站首页>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);
边栏推荐
- 为了交通安全,可以做些什么?
- (shuttle) navigation return interception: willpopscope
- Cover fake big empty talk in robot material sorting
- Dayu200 experience officer homepage AITO video & Canvas drawing dashboard (ETS)
- European Bioinformatics Institute 2021 highlights report released: nearly 1million proteins have been predicted by alphafold
- 监控界的最强王者,没有之一!
- 同构+跨端,懂得小程序+kbone+finclip就够了!
- 实现多彩线条摆出心形
- Gpt-3 is a peer review online when it has been submitted for its own research
- Redis 持久化机制
猜你喜欢
[launched in the whole network] redis series 3: high availability of master-slave architecture
Cloud native (32) | kubernetes introduction to platform storage system
COSCon'22 社区召集令来啦!Open the World,邀请所有社区一起拥抱开源,打开新世界~
Motion capture for snake motion analysis and snake robot development
B站大佬用我的世界搞出卷積神經網絡,LeCun轉發!爆肝6個月,播放破百萬
Slide the uniapp to a certain height and fix an element to the top effect demo (organize)
室内LED显示屏应该怎么选择?这5点注意事项必须考虑在内
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon
Cover fake big empty talk in robot material sorting
On the problems of born charge and non analytical correction in phonon and heat transport calculations
随机推荐
石墨文档:4大对策解决企业文件信息安全问题
Chapter 19 using work queue manager (2)
Let's see through the network i/o model from beginning to end
Redis persistence mechanism
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
memcached
docker启动mysql及-eMYSQL_ROOT_PASSWORD=my-secret-pw问题解决
UE4 blueprint learning chapter (IV) -- process control forloop and whileloop
What can be done for traffic safety?
PDF批量拆分、合并、书签提取、书签写入小工具
Flutter life cycle
Hard core observation 545 50 years ago, Apollo 15 made a feather landing experiment on the moon
Pdf batch splitting, merging, bookmark extraction, bookmark writing gadget
Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million
Uniapp setting background image effect demo (sorting)
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
mysql拆分字符串作为查询条件的示例代码
Dayu200 experience officer runs the intelligent drying system page based on arkui ETS on dayu200
企業不想換掉用了十年的老系統
C three ways to realize socket data reception