通过js的splice删除对象数组中指定条件的对象内容代码示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">@b@<html xmlns="http://www.w3.org/1999/xhtml">@b@<head> @b@<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> @b@<script type="text/javascript"> @b@ let objArray = [{@b@ value: "2022-03-20",@b@ id: 1@b@ }, {@b@ value: "2022-03-21",@b@ id: 2@b@ }, {@b@ value: "2022-03-22",@b@ id: 3@b@ }, {@b@ value: "2022-03-23",@b@ id: 4@b@ }, {@b@ value: "2022-03-24",@b@ id: 5@b@ }, {@b@ value: "2022-03-25",@b@ id: 6@b@ }];@b@@b@ //删除指定条件对象项@b@ objArray.some((item, i) => {@b@ if (item.id == 3) {@b@ objArray.splice(i, 1)@b@ return true @b@ }@b@ }) @b@ @b@ for(var obj of objArray){@b@ document.write("<p>"+obj.id+":"+obj.value+"</p>"); @b@ }@b@ @b@@b@</script>@b@@b@</head>@b@<body > @b@</body>@b@</html>
输出结果如下
1:2022-03-20@b@2:2022-03-21@b@4:2022-03-23@b@5:2022-03-24@b@6:2022-03-25