【发布时间】:2017-02-14 20:31:33
【问题描述】:
我想摆脱“未定义”并平均输出到控制台的 priceList 数组值。我使用 https://experts.shopify.com/designers 网页在 Chrome 控制台中应用此代码。感谢您的帮助!
//selects the all of the designer cards
var experts = document.querySelectorAll('.expert-card__content');
//This tells us how many designer cards there are
var expertsQty = experts.length;
var expertContent =document.getElementsByClassName("expert-list-summary txt--minor");
//expertContent[0].innerText
var i;
var priceMedian;
var prices;
var priceList = 0;
for(i=0; i<experts.length; i++){
//Grabs the content
var str = expertContent[i].innerText;
//This determines the position of the last $ in the text
var strPosition = expertContent[i].innerText.lastIndexOf("$");
//This goes to the position of the $ and shows the 1 word after it.
var expertPrice= str.substring(strPosition + 1);
//iterate through expert content
parseInt(expertPrice);
parseInt(prices);
priceList = prices += expertPrice;
}
【问题讨论】:
-
你的问题有点含糊。你到底想知道什么?
-
parseInt接受一个字符串并返回一个数字!应该这样使用:var number = parseInt("45");! -
加上网站上的数字是
3,456这个格式,这不是一个有效的数字!
标签: javascript arrays average