gpt4 book ai didi

javascript - 如何从数组中删除 json 元素?

转载 作者:行者123 更新时间:2023-12-01 03:57:57 25 4
gpt4 key购买 nike

因此,我使用 REST 沙箱 API 从状态数组中删除“Call”,并且该数组包含所有 JSON,不确定使用什么来删除它。

请注意:这是通过 HTTP 从 Lua 脚本运行的请求进行连接。

网站:getsandbox.com

代码如下:

//Store Calls
state.calls = state.calls || []
var calls = state.calls;



/*
|
| Create Call
V
*/

Sandbox.define('/new/call/','POST', function(req, res){

var gameid = req.get("Roblox-Id");
var person = req.body.split(" ")[0];
var reason = req.body.split(" ")[1];
var comp = {
gameid: gameid,
player: person,
callreason: reason
};

calls.push(comp);
// Set the type of response, sets the content type.
res.type('text/plain');

// Set the status code of the response.
res.status(200);

// Send the response body.
res.send('Request Accepted');
});

/*
|
| Get Calls
V
*/

Sandbox.define('/get/calls/','GET', function(req, res){
// Check the request, make sure it is a compatible type

// Set the type of response, sets the content type.
res.type('application/json');

// Set the status code of the response.
res.status(200);

// Send the response body.
res.send(calls);
})

/*
|
| Delete
v
*/

Sandbox.define('/data/delete/{gameid}/','GET', function(req, res){
for(i=0;i<calls.length;i++){
calls[i].pop();
}

// Set the type of response, sets the content type.
res.type('text/plain');

// Set the status code of the response.
res.status(200);

// Send the response body.
res.send('Successful');
})

最佳答案

找到调用索引并使用以下内容:

calls.splice(index, 1);

关于javascript - 如何从数组中删除 json 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42476388/

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