Guest User

Untitled

a guest
May 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function foo(bar) {
  2. if (bar > 1) {
  3. return [1,2,3];
  4. } else {
  5. return 1;
  6. }
  7. }
  8.  
  9. function isArray(obj) {
  10. return Object.prototype.toString.call(obj) === '[object Array]';
  11. }
  12.  
  13. if (my_value && typeof my_value === 'object' && typeof my_value.length === 'number' &&
  14. !(my_value.propertyIsEnumerable('length')) { // my_value is truly an array! }
  15.  
  16. function isarray(my_value) {
  17.  
  18. if (my_value && typeof my_value === 'object' && typeof my_value.length === 'number' &&
  19. !(my_value.propertyIsEnumerable('length'))
  20. { return true; }
  21. else { return false; }
  22. }
  23.  
  24. if(foo(1) instanceof Array)
  25. // You have an Array
  26. else
  27. // You don't
  28.  
  29. function is_array_compliant(obj){
  30. return obj && typeof obj.length != 'undefined';
  31. }
Add Comment
Please, Sign In to add comment