Skip to main content
Rollback to Revision 7
Source Link
user229044
  • 240.8k
  • 41
  • 346
  • 350

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

Compare Methods

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

Compare Methods

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

Added comparison
Source Link
dthree
  • 20.9k
  • 14
  • 81
  • 114

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

Compare Methods

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

Compare Methods

Rollback to Revision 5
Source Link
Brett Bender
  • 19.8k
  • 2
  • 40
  • 46

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

added 4 characters in body
Source Link
Arpit Aggarwal
  • 29.5k
  • 16
  • 97
  • 110
Loading
Added note to include ES5 convenience method for this
Source Link
Brett Bender
  • 19.8k
  • 2
  • 40
  • 46
Loading
Indentation
Source Link
Brett Bender
  • 19.8k
  • 2
  • 40
  • 46
Loading
Rollback to Revision 1
Source Link
Brett Bender
  • 19.8k
  • 2
  • 40
  • 46
Loading
added 6 characters in body
Source Link
Nathaniel Ford
  • 21.3k
  • 20
  • 98
  • 112
Loading
Source Link
Brett Bender
  • 19.8k
  • 2
  • 40
  • 46
Loading