简体   繁体   English

如何编写for循环以从对象中获取属性并将其插入到函数javascript中

[英]How to write for loop to take property from object and insert it in function javascript

I am beginner in programming and I wish someone help me on this code.我是编程初学者,我希望有人帮助我解决此代码。

My code is:-我的代码是:-

var i = Object.keys(mws.Result.InventorySupplyList.member).length
console.log(i)
a0 = mws.Result.InventorySupplyList.member[0].ASIN
a1 = mws.Result.InventorySupplyList.member[1]
const amazonScraper = require('amazon-buddy');
(async () => {
    try {
        // Get single product details by using ASIN id
        const product_by_asin_0 = await amazonScraper.asin({ asin: a0 });
        console.log(product_by_asin_0)
    } catch (error) {
        console.log(error);
    }
})();
(async () => {
    try {
       // Get single product details by using ASIN id
        const product_by_asin_1 = await amazonScraper.asin({ asin: a0 });
        console.log(product_by_asin_1)
    } catch (error) {
        console.log(error);
    }
})();

mws is JOSN object mws 是 JOSN 对象

const mws = {
    "ResponseMetadata": {
      "RequestId": "e8698ffa-8e59-11df-9acb-230ae7a8b736"
    },
    "Result": {
      "InventorySupplyList": {
        "member": [
          {
            "SellerSKU": "SampleSKU1",
            "ASIN": "B00000K3CQ",
            "TotalSupplyQuantity": "20",
            "FNSKU": "X0000000FM",
            "Condition": "NewItem",
            "SupplyDetail": {},
            "InStockSupplyQuantity": "15",
            "EarliestAvailability": {
              "TimepointType": "Immediately"
            }
          },
          {
            "SellerSKU": "SampleSKU2",
            "ASIN": "B00004RWQR",
            "TotalSupplyQuantity": "0",
            "FNSKU": "X00008FZR1",
            "Condition": "UsedLikeNew",
            "SupplyDetail": {},
            "InStockSupplyQuantity": "0"
          }
        ]
      }
    },
    "Headers": {
      "x-mws-quota-max": "",
      "x-mws-quota-remaining": "",
      "x-mws-quota-resetson": "",
      "x-mws-timestamp": "2018-09-05T06:13:00.276Z",
      "content-type": "text/xml",
      "content-charset": "",
      "content-length": "",
      "content-md5": "",
      "date": ""
    },
    "StatusCode": 200
  }

I want to take the ASIN from the mws object and insert it in the other code which will scrape the details from amazon.com , as you notice already that I figured out the object mws has 2 ASIN and did insert it manually in the scraper.我想从 mws 对象中获取 ASIN 并将其插入其他代码中,该代码将从 amazon.com 抓取详细信息,因为您已经注意到我发现对象 mws 有 2 个 ASIN 并确实将其手动插入到刮板中。 If you can help me how to write for loop to do the code in what ever ASINs.如果您能帮助我如何编写 for 循环以在任何 ASIN 中执行代码。

const Promise = require('bluebird');
const amazonScraper = require('amazon-buddy');
const requests = Promise.all(Object.keys(mws["Result"]["InventorySupplyList"]["member"])
  .map(member => amazonScraper.asin({ asin: member["ASIN"] }));)
requests.then(responces => console.log(responces))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何编写将数组作为参数的javascript循环函数? - How to write javascript loop function that will take an array as a parametr? JavaScript:在循环期间将属性插入 object - JavaScript: Insert property into an object during loop 查询将函数写入 javascript Object JSDoc 属性 - Inquiry to write function to javascript Object JSDoc property 如何从对象传递属性名称作为JavaScript函数的参数? - How to pass a property name from an object as a parameter in function in javascript? 如何使用 javascript 访问从 function 返回的 object 的属性? - How to access a property of an object which is returned from a function using javascript? 如何从 javascript 中的字符串创建 object 属性 function? - How to create an object property function from a string in javascript? 如何在javascript中从函数内部访问对象属性,是否可能? - how to access object property from inside function in javascript, is it possible? 如何停止将函数视为javascript对象中的属性? - How to stop a function from being treated as a property in a javascript object? 如何循环对象的javascript object并找到一个属性 - How to loop javascript object of objects and find a property javascript函数,如何在document.write中获取变量? - javascript function, how to take the variable within document.write?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM