212
I Use This!
Very Low Activity

News

Analyzed 1 day ago. based on code collected 1 day ago.
Posted over 13 years ago by Kizi
Thanks for share, this is very useful ;)
Posted over 13 years ago by Kizi
Thanks for the input, but we'd really want it to work like in PHP.
Posted over 13 years ago by SnunniSanuh
Posted over 13 years ago by Anum
It gave me [object Object] as an output, i dont understand whats happening here.
Posted over 13 years ago by CoursesWeb
Hi, This is a comment to correct the function posted below. That function has an error, it returns the last key, eaven the value not match. Sorry, here's the corrected version: function array_search(val, array) { if(typeof(array) === 'array' || ... [More] typeof(array) === 'object') { var rekey; for(var indice in array) { if(array[indice] == val) { rekey = indice; break; } } return rekey; } } [Less]
Posted over 13 years ago by CoursesWeb
Hi, For a simple array_search function, without the third parameter, i use made this variant (works with array and objects: function array_search(val, array) { if(typeof(array) === 'array' || typeof(array) === 'object') { for(var indice in array) { if(array[indice] == val) break; } if(indice) return indice; } }
Posted over 13 years ago by CoursesWeb
Hi, For is_float i use this version: function is_float(n) { return n===+n && n!==(n|0); } - is_float() doesn't always work if you are validating form input. This is because form inputs are strings, even if the user typed a number.
Posted over 13 years ago by CoursesWeb
Hi, For is_int i use this version: function is_int(n) { return typeof(n)==="number" && Math.round(n) == n; }
Posted over 13 years ago by CoursesWeb
Hi, To get and also check the type of a variable, I use this: function gettype(obj, type) { // www.coursesweb.net/javascript/ // if type not specified (null), returns a string with the object (obj) type if(type == null) return ... [More] obj.constructor.toString().split(' ')[1].replace(/\(\)/g,'').toLowerCase(); else { //returns true if is it is type, else, false if (obj.constructor.toString().match(new RegExp(type, 'i', 'g'))) return true; else return false; } } - If the type of "obj" is the name specified in the "type" parameter, the function returns True, otherwise, returns False. - If no argument specified for "type", the function returns a string with the type of "obj" [Less]
Posted over 13 years ago by CoursesWeb
Hi, For is_bool, i use: function is_bool(obj) { return (obj === true || obj === false); }