Skip to content

Instantly share code, notes, and snippets.

@ufocoder
Created October 21, 2018 11:57
Show Gist options
  • Select an option

  • Save ufocoder/ea352b1cee49f77ca189ce57c3dda2bf to your computer and use it in GitHub Desktop.

Select an option

Save ufocoder/ea352b1cee49f77ca189ce57c3dda2bf to your computer and use it in GitHub Desktop.
// Метод #1: свойство constructor
// Ненадежный метод
function isArray(value) {
return typeof value == 'object' && value.constructor === Array;
}
// Метод #2: instanceof
// Ненадежный метод в связи с возможностью изменения прототипа объекта
// Непредвиденные результаты при работе с `iframe`
function isArray(value) {
return value instanceof Array;
}
// Метод #3: Object.prototype.toString()
// Улучшенная проверка плюс очень похода на функцию ES6 Array.isArray()
function isArray(value) {
return Object.prototype.toString.call(value) === '[object Array]';
}
// Метод #4: ES6 Array.isArray()
function isArray(value) {
return Array.isArray(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment