get jquery slider all values between the range

759 views Asked by At

I need help in jquery slider range for getting between values like, i have defined array var valMap = [0, 25, 50, 100, 250, 500]; if user select 0 to 100 so i want to print or get the between numbers right now i can get only two values first value and end value, i have post my code kindly help me

$(function() {
    var valMap = [0, 25, 50, 100, 250, 500];
    $("#lens-range").slider({
        min: 0,
        max: valMap.length - 1,
        values: [0, 1],
        slide: function(event, ui) {
            $("#lensrange").val('Miles: ' + valMap[ui.values[0]] + ' - ' + valMap[ui.values[1]]);
            console.log($.inArray(ui.value, valMap) != -1);
        },
        stop: function(event, ui) {
            for (var i = 0; i < valMap.length; i++) {
                console.log(valMap[ui.values[i]]);

            }
        }
    });
    $("#lensrange").val('Miles: ' + valMap[$("#lens-range").slider("values", 0)] + ' - ' + valMap[$("#lens-range").slider("values", 1)]);
});
1

There are 1 answers

4
Julien Grégoire On

You could use slice(). See http://www.w3schools.com/jsref/jsref_slice_array.asp

Like this:

var rangeArray = valMap.slice(ui.value[0], ui.value[1])

EDIT:

Slice returns from start index until, not including, end index. To include end index simply call it like this:

var rangeArray = valMap.slice(ui.value[0], ui.value[1]+1)