我正在从像这样的数组中创建一个对象
var val = $(this).val();
var type = " " + $("#backing").val() + " ";
var arr = $.extend({}, comb_arr[type]);
结果
var arr = {"1-4 ": "$10.10 ", "5-9 ": "$8.34 ", "10-24 ": "$7.71 ", "25-49 ": "$7.21 "}
当我通过输出运行以下代码时未定义
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if(/\d+\-\d+/.test(s)){
var range = s.split("-");
if(val >= parseInt(range[0]) && val <= parseInt(range[1])){
a = comb_arr[c];
}
}else{
s = s.replace(/\D/g, "");
if(val >= s){
a = comb_arr[c];
}
}
return a;
},0);
欢迎所有想法!