Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype Expressing Range

previous next AddThis Social Bookmark Button


Prototype Ranges represent an interval of values. The preferred way to obtain a range is to use the $R utility function.

You can create a big range of values using a simple syntax as follows:

$R(1, 10).inspect();

$R('a', 'e').inspect();

This will produce following result:

['1, 2, 3, 4, 5, 6, 7, 8, 9, 10']

['a', 'b', 'c', 'd', 'e']

The include() Method

This method determines whether the value is included in the range:



Return Value :

  • If value is included then returns a true value otherwise false.


<title>Prototype examples</title>
   <script type="text/javascript" 

function showResult()
   alert ( "Test 1 : " + $R(1, 10).include(5));
   // Returns true
   alert ( "Test 2 : " + $R('a', 'h').include('x'));
   // Returns flase



  <p>Click the button to see the result.</p>
  <br />

  <br />
  <input type="button" value="Result" onclick="showResult();"/>


To understand it in better way you can Try it yourself.

previous next Printer Friendly