Remember that jQuery is a DOM library, not a general purpose JavaScript utility library. When the thing you're doing is unrelated to the DOM, don't look for the solution in jQuery. It probably won't be there, or if it appears to be there, it will probably surprise you because it was coded specifically for DOM use. Either code your own solution or find one that somebody has coded.
If I understand what you're trying to do, what you're looking for is [].concat(...). For example: console.log( [].concat(0) ); // [0] console.log( [].concat(1) ); // [1] console.log( [].concat([2,3]) ); // [2,3] Or you can make that into a function: function copyArray() { return Array.prototype.concat.apply( [], arguments ); } console.log( copyArray(0) ); // [0] console.log( copyArray(1) ); // [1] console.log( copyArray([2,3]) ); // [2,3] -Mike On Mon, Nov 2, 2009 at 2:03 PM, Xavier Shay <xavier.s...@gmail.com> wrote: > > > On Nov 2, 1:28 am, John Resig <jere...@gmail.com> wrote: > > This changed slightly in the latest nightlies - if you do $(0) it'll > > be as if you did $() or $([]). As of now any false-ish value will give > > you an empty jQuery set. > > > > Considering that there is no intended behavior for passing in a number > > to the jQuery object this seems fine to me. > > > > I'm curious - why were you passing in a number to the jQuery object? I > > could sort of, kind of, understand passing in an array of values - but > > just one number doesn't make sense. > It was an array of values, but that array could also be a number, > which was then converted into an array, except for the 0 case. > This is bad form, relying on undocumented behaviour. I have since > fixed my code, but still curious. > Principle of least surprise says that $(1) and $(0) should be > consistent. To match the nightlies, perhaps $(1) should be an empty > jQuery object? > > > Did you find this by accident, or are you writing code that depends on > > $(2) returning 2? > By accident, found that $(2) returns [2], so using it as a conversion > (though no longer, as above) > > Xavier > > -- > > You received this message because you are subscribed to the Google Groups > "jQuery Development" group. > To post to this group, send email to jquery-...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-dev+unsubscr...@googlegroups.com<jquery-dev%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/jquery-dev?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-...@googlegroups.com. To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en.