Monkeymajiks
Monkeymajiks

Reputation: 11

testing for all values in an array over a certain value

I have an array of values that are produced from an equation.

e.g.

testArray = [1,2,3,4,5,6,7,8,9,10];

What I want to do is write a function to look for all the values over a particular value and output the result.

So for example, in the above testArray how would I return all the values over 7 (8,9, 10 only not including 7)?

Happy for the response to use Javascript and/or Jquery.

Thanks in advance.

Upvotes: 1

Views: 59

Answers (1)

alex
alex

Reputation: 490253

You could use filter().

var testArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].filter(function(element) {
    return element > 7;
});

jsFiddle.

Upvotes: 2

Related Questions