To pass a data type that changes (from an array to an integer) to the same function, and then before changing its value, check the data type by looking at the method below using instanceof Array, is there a better / more efficient way?
function foo(x) { if (x instanceof Array) { for(i=0;i<x.length;i++){ x[i].bar = '1'; x[i].baz = '2'; } } else{ x.bar = '1'; x.baz = '2'; } }
Thanks:)
Aaron source share