Jquery : Set Value for a Range in a Dictionary -


i want set values range in jquery dictionary object somthing this

var temp_dict = {'1-10': 'woolen', '11-25':'light woolen', '26-36':'light cotton'} 

here keys 1-10, 11-25, 26-36 different ranges of temprature. want store in dictionary , call them :

alert(temp_dict[15]); 

so checks in range , returns appropriate result.

is there way achieve this??

function gettemp(t) {     (var key in temp_dict) {         var range = key.split("-");         if (t >= range[0] && t <= range[1])             return temp_dict[key];     } }  var temp = gettemp(15); 

demo: http://jsfiddle.net/wpxdx/


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -