gpt4 book ai didi

javascript - 为什么 array.splice 总是删除最后一个元素?

转载 作者:行者123 更新时间:2023-11-29 23:20:31 25 4
gpt4 key购买 nike

<分区>

我这里有这段代码

 cart.splice(1, 1);      

其中 cart 是一个数组。无论我在 splice 的第一个元素中给出什么,它总是会删除最后一个元素。如何解决它,为什么会发生?我的阵列看起来像这样:-

[{
"productId": "400002",
"productQuantity": 3,
"productName": "Annadata Organic Brinjal Long Purple",
"productPrice": "7",
"productCategory": "Fruits & Vegetables",
"shopId": "10375",
"shopName": "Dubori",
"shopDelivery": "1",
"delivery": 1,
"variant": "{\"id\":400002,\"image\":\"https:\\\/\\\/s3.ap-south-1.amazonaws.com\\\/doorhopperimg\\\/products\\\/83c7dc09da8eceae96fd9bcbd819e43b.jpg\",\"quantity\":\"250gm\",\"price\":7,\"afterTax\":null,\"stock\":-2,\"description\":\"Annadata Organic Brinjal Long Purple      Rs.7\\\/250gm\",\"barcode\":\"10375400002\"}"
}, {
"productId": "400006",
"productQuantity": "1",
"productName": "Apple (Kashmiri)",
"productPrice": "33",
"productCategory": "Fruits & Vegetables",
"shopId": "10375",
"shopName": "Dubori",
"shopDelivery": "1",
"delivery": 1,
"variant": "{\"id\":400006,\"image\":\"https:\\\/\\\/s3.ap-south-1.amazonaws.com\\\/doorhopperimg\\\/products\\\/07e8be62843d3c9145d572df70fe06d4.jpg\",\"quantity\":\"250gm\",\"price\":33,\"afterTax\":null,\"stock\":-2,\"description\":\"Apple (Kashmiri)      Rs.33\\\/250gm\",\"barcode\":\"10375400006\"}"
}]

现在它只有两个元素,但应该有更多

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com