• How to find out if an array is a full-fledged array, and not a string or some kind of "non-mass"?

I was expecting some kind of var_dump function like in PHP, but in JS I cannot understand what type of array data is and how to determine in general that the array is real and you can use standard array methods for it.

  • How to know the type of an array variable and change it to another?

My array stores thousands of data, but they are partly moderated during the script process and perhaps their type was changed due to this. Is there some way to know the data type and change it to the required one?

  • console.log, typeof not? - sepgg

1 answer 1

How to find out if an array is a full-fledged array, and not a string or some kind of "non-mass"?

I don’t know what “nedomassiv” is, but you can check whether an object is an array or not using the Array.isArray() method.

I was expecting some kind of var_dump function like in PHP

The analogue of the var_dump() function from PHP in JavaScript is console.log() . The result will be displayed in the browser console, which is opened by pressing the Ctrl + Shift + I key combination.

How to know the type of an array variable

To determine the type of a variable, the typeof operator is used or, as rightly noted in the comments, instanceof . Please note that when checking through typeof ordinary objects and arrays in JavaScript are of the same type - object . To identify an array, you can use the Array.isArray() method mentioned above or the same instanceof .

  • to check for better instanceof - Grundy
  • I suspect that the "nedomassiv" is the NodeList and other massive-like environment objects - Duck Learns to Take Cover
  • @MorelyPortableUtk, in fact it is any object with the length property and numeric keys - Grundy
  • console.log() does not seem to give out information about the data type in the array. var_dump says the data type, in addition to the array listing. - Telion
  • @Grundy probably is. I found this word in the English version of the portal and decided that it could be quite understandable to describe the current question. - Telion