当前位置:网站首页>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
- [step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
- 存币生息理财dapp系统开发案例演示
- Pdf batch splitting, merging, bookmark extraction, bookmark writing gadget
- Cocoscreator+typescripts write an object pool by themselves
- 机器人材料整理中的套-假-大-空话
- Motion capture for snake motion analysis and snake robot development
- BasicVSR_ Plusplus master test videos and pictures
- NPM cannot install sharp
- Some suggestions for foreign lead2022 in the second half of the year
猜你喜欢
随机推荐
让我们,从头到尾,通透网络I/O模型
The statement that allows full table scanning does not seem to take effect set odps sql. allow. fullscan=true; I
(flutter2) as import old project error: inheritfromwidgetofexacttype
Cocoscreator+typescripts write an object pool by themselves
Method of canceling automatic watermarking of uploaded pictures by CSDN
A few suggestions for making rust library more beautiful! Have you learned?
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
Chapter 19 using work queue manager (2)
欧洲生物信息研究所2021亮点报告发布:采用AlphaFold已预测出近1百万个蛋白质
使用MitmProxy离线缓存360度全景网页
Interview question: AOF rewriting mechanism, redis interview must ask!!!
Is "applet container technology" a gimmick or a new outlet?
AcWing 4299. Delete point
CUDA exploration
【全网首发】Redis系列3:高可用之主从架构的
Financial professionals must read book series 6: equity investment (based on the outline and framework of the CFA exam)
Redis persistence mechanism
Cloud native technology container knowledge points
Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
CSDN 上传图片取消自动加水印的方法







