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' ||
|
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
|
Posted
over 13 years
ago
by
CoursesWeb
Hi,
For is_bool, i use:
function is_bool(obj) {
return (obj === true || obj === false);
}
|