views:

87

answers:

1

So..

I am passing data to a function that handles strings and numbers differently.

I would LIKE to be able to pass an array of values and detect what the types of each value is.

row[0] = 23;
row[1] = "this is a string... look at it be a string!";
row[2] = true;

$.each(row, function(){
  alert(typeof(this));
  //alerts object
});

Is it possible to detect the "actual" datatypes in a given row?

+2  A: 

Try

var row = [ 23, "this is a string", true ];

$.each(row, function (index,item) {
    alert(typeof(item));
});

// Alerts "number", "string", "boolean"

Whenever possible I try to avoid using "this" in callbacks and using explicit arguments is usually clearer and more predictable.

Rich
dead on. thanks...
Derek Adair
You're welcome. Now I'm going to look in jQuery's source code to learn why your version doesn't work...
Rich
`this` is always an object. *Always*. That is all.
Roatin Marth
@Roatin I never knew that. Thank you.
Rich
nor did i.... It makes sense though.
Derek Adair
...even when you do something like... `var notThis = this` notThis is an object.
Derek Adair