I need to find specific array item from amount according **"1000,2000,3000|100,200,300"** eg..,(range|amount) string by input amount
like..,
--Range-- = --Output--
0 to 1000 = 0<br />
1001 to 2000 = 100<br />
2001 to 3000 = 200<br />
3000 onwards = 300
I did for this
var input = 3001; // (test inputs 1000,1500,2200)
var output=0;
var str = "1000,2000,3000|100,200,300";
var range = str.split('|')[0].split(',');
var amount = str.split('|')[1].split(',');
for(var i=0;i<range.length;i++){
var checkRange= parseInt(range[i]);
if(input<=checkRange){
output=i!=0?(amount[i-1]):0;
break;
}
}
console.log(output)
this code is working fine only if input amount in between 0 to last array item(range 0-3000, input is >=3000 ), but if input amount(<3000) is greater than last array item(range) then returning 0
Please help to solve this stuff!