当前位置:网站首页>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);边栏推荐
猜你喜欢

Why are some people still poor and living at the bottom of society even though they have been working hard?

专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统

ACL 2022 | small sample ner of sequence annotation: dual tower Bert model integrating tag semantics

MySQL authentication bypass vulnerability (cve-2012-2122)

Use mitmproxy to cache 360 degree panoramic web pages offline

NFTScan 开发者平台推出 Pro API 商业化服务

Nftscan Developer Platform launches Pro API commercial services

Flutter life cycle

Method of canceling automatic watermarking of uploaded pictures by CSDN

【全网首发】Redis系列3:高可用之主从架构的
随机推荐
Traversal of a tree in first order, middle order, and then order
#DAYU200体验官# 首页aito视频&Canvas绘制仪表盘(ets)
Thinkphp5 multi table associative query method join queries two database tables, and the query results are spliced and returned
Case recommendation: An Qing works with partners to ensure that the "smart court" is more efficient
UVa 11732 – strcmp() Anyone?
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
[step on pit collection] attempting to deserialize object on CUDA device+buff/cache occupy too much +pad_ sequence
Devsecops software R & D security practice - release
BasicVSR_ Plusplus master test videos and pictures
Method of canceling automatic watermarking of uploaded pictures by CSDN
Project duplicate template
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
Redis 持久化机制
云原生(三十二) | Kubernetes篇之平台存储系统介绍
Demonstration of the development case of DAPP system for money deposit and interest bearing financial management
[compilation principle] LR (0) analyzer half done
On the problems of born charge and non analytical correction in phonon and heat transport calculations
Improving Multimodal Accuracy Through Modality Pre-training and Attention
DevSecOps软件研发安全实践——发布篇
ICLR 2022 | 基于对抗自注意力机制的预训练语言模型