所以这是我的代码,它在 NodeJS 而不是 javascript 中:
while (otn !== -1) {
var li= inventory.length - 1;
while (li !== -1){
li = li- 1;
if (inventory[li].market_name === orderitemname[otn]){
console.log("Add item to trade " + orderitemname[otn]);
offer.addMyItem(inventory[li]);
console.log(inventory[li])
delete inventory[li];
//Close everything
所以一切正常,除了delete inventory[li]
,它的作用是从 json 中删除值,但是当 while 循环再次运行时,程序尝试从相同的值读取值并崩溃,所以有没有一种我们可以完全喜欢的方法删除它(以下一堆代码),然后甚至没有列出?顺便说一句,这是我的 JSON:
CEconItem {
appid: 730,
contextid: '2',
assetid: '13799167798',
classid: '506854340',
instanceid: '188530139',
amount: 1,
pos: 1,
id: '13799167798',
background_color: '',
icon_url: blah,
icon_url_large: blah,
descriptions: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
tradable: true,
actions: [ [Object] ],
name: 'P90 | Module',
name_color: 'D2D2D2',
type: 'Mil-Spec Grade SMG',
market_name: 'P90 | Module (Factory New)',
market_hash_name: 'P90 | Module (Factory New)',
market_actions: [ [Object] ],
commodity: false,
market_tradable_restriction: 7,
marketable: true,
tags: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
is_currency: false,
market_marketable_restriction: 0,
fraudwarnings: [] },
And a lot of these...
任何帮助将不胜感激:) 谢谢!
PS:我是个菜鸟,如果我错过了像蛋糕这样简单的东西,请不要烤我:)