Melonos Posted September 29, 2016 Report Share Posted September 29, 2016 When I do itemsToGive.market_name_hashname it only takes the first item in the trade.what if I want for all of them? Please give an example. Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted September 29, 2016 Report Share Posted September 29, 2016 itemsToGive is an array. Quote Link to comment Share on other sites More sharing options...
Melonos Posted September 29, 2016 Author Report Share Posted September 29, 2016 [ EconItem { appid: 730, contextid: '2', assetid: '7584018068', classid: '926978479', instanceid: '0', amount: 1, missing: false, icon_url: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsUFJ5KBFZv668FFAuhqSaKWtEu43mxtbbk6b1a77Twm4Iu8Yl3bCU9Imii1Xt80M5MmD7JZjVLFH-6VnQJQ', icon_url_large: '', icon_drag_url: '', name: 'Chroma 2 Case', market_hash_name: 'Chroma 2 Case', market_name: 'Chroma 2 Case', name_color: 'D2D2D2', background_color: '', type: 'Base Grade Container', tradable: true, marketable: true, commodity: true, market_tradable_restriction: 7, fraudwarnings: [], descriptions: [ [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object] ], owner_descriptions: [], tags: [ [Object], [Object], [Object], [Object] ], id: '7584018068', actions: [], owner_actions: [], market_marketable_restriction: 0 }, EconItem { appid: 730, contextid: '2', assetid: '7582569339', classid: '1690096482', instanceid: '0', amount: 1, missing: false, icon_url: '-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsUFJ5KBFZv668FFYynaSdJGhE74y0wNWIw_OlNuvXkDpSuZQmi--SrN-h3gey-Uo6YWmlIoCLMlhplhFFvwI', icon_url_large: '', icon_drag_url: '', name: 'Chroma 3 Case', market_hash_name: 'Chroma 3 Case', market_name: 'Chroma 3 Case', name_color: 'D2D2D2', background_color: '', type: 'Base Grade Container', tradable: true, marketable: true, commodity: true, market_tradable_restriction: 7, fraudwarnings: [], descriptions: [ [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object], [Object] ], owner_descriptions: [], tags: [ [Object], [Object], [Object], [Object] ], id: '7582569339', actions: [], owner_actions: [], market_marketable_restriction: 0 } ]It outputs this.And I wanna get both names,and but them into two variables. CASE1 = CASE1 NAMECASE2 = CASE2 NAME Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted September 29, 2016 Report Share Posted September 29, 2016 Do you know what an array is? Quote Link to comment Share on other sites More sharing options...
adma Posted September 30, 2016 Report Share Posted September 30, 2016 (edited) If you want to get the market hash names of each item you're giving, you would probably use forEach or a for loop to cycle through the itemsToGive array ...e.g manager.on('newOffer', function(offer) { offer.itemsToGive.forEach(function(item) { console.log("Item to give : " + item.market_hash_name); // Items to give: Chroma 2 Case }); }); a for ... of loop (edited from for..in loop) manager.on('newOffer', function(offer) { for (var item of offer.itemsToGive) { console.log("Items to give : " + item.market_hash_name); // Items to give: Chroma 2 Case } }); a regular for loop manager.on('newOffer', function(offer) { for (var i = 0; i < offer.itemsToGive.length; i++) { console.log("Items to give #" + i + " : " + offer.itemsToGive[i].market_hash_name); // Items to give #1 : Chroma 2 Case } });Same deal will apply for itemsToReceive ... or any other array you wanted to cycle through read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration Edited September 30, 2016 by adma Melonos 1 Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted September 30, 2016 Report Share Posted September 30, 2016 It's not recommended to use for ... in on an array. Quote Link to comment Share on other sites More sharing options...
adma Posted September 30, 2016 Report Share Posted September 30, 2016 (edited) Alright, cheers McKay. Updated my answer with a for..of loop instead. Edited September 30, 2016 by adma Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.