Q:

What's the best way to sort function inputs based on type in Javascript?

I've got a function with several inputs, which I would like to be optional in calling the function. Each input is of a different type, such as string, array, or number. With code like this:
function doStuff(str, arr, num){
    if typeof(str) != 'undefined' { $('#stringDiv').text(str)}

    if typeof(arr) != 'undefined' {
        for(var i=0; i < arr.length; i++){
            $('<li>').text(arr[i]).appendTo('#arrayUl')
        }
    }

    if typeof(num) != 'undefined' { $('#numberDiv').text(num)}
}

jQuery(document).ready(function() {
    doStuff("i'm a string", [1,2,3,4,5], 7)
})

I can account for the fact that my arguments might be optional, but not for the fact that, if I am missing arr, then my numeric argument (num) will come second, not third.
To get around this, I can also dump my inputs into an array, and then sort through the array and look for this of each type, like I do in this fiddle. This seems sloppy, and, based on the number of libraries that I've seen that do this in their functions, it seems like there's probably a better way. Is there a better way to do this? Or is looping through arguments and hunting for types my best bet?

A:

You could leave off all parameters and use the arguments list to see what was passed. 
But, a better approach would be to create an object like this:
{
    str: "i'm a string",
    arr: [1, 2, 3, 4],
    num: 3.14
}

And then inspect the object for those keys:
function doStuff(args):
    if ('str' in args) {
        $('#stringDiv').text(args.str);
    }

