We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

Method Array.isArray() mengembalikan nilai true jika objek adalah array, false jika bukan.

Sintaks

Array.isArray(obj)

Parameter

obj
Objek yang di cek.

Deskripsi

Baca artikel “Determining with absolute accuracy whether or not a JavaScript object is an array” untuk detailnya.

Contoh

// semuanya mengembalikan nilai true
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
// Sekedar fakta : Array.prototype sendiri adalah array:
Array.isArray(Array.prototype); 

// semua mengembalikan nilai false
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(17);
Array.isArray('Array');
Array.isArray(true);
Array.isArray(false);
Array.isArray({ __proto__: Array.prototype });

Polyfill

Jalankan kode berikut sebelum kode lain untuk membuat method Array.isArray() jika secara native tidak tersedia.

if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}

Spesifikasi

Spesifikasi Status Comment
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.isArray' in that specification.
Standard Initial definition. Implemented in JavaScript 1.8.5.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Array.isArray' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'Array.isArray' in that specification.
Draft  

Kompabilitas Browser

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 4.0 (2.0) 9 10.5 5
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 4.0 (2.0) (Yes) (Yes) (Yes)

Lihat Juga

Tag Dokumen dan Kontributor

Kontributor untuk laman ini: bekti
Terakhir diperbarui oleh: bekti,