As I am a beginner and I saw few videos on youtube they are saying basically everything is an object even an array also so I just want to know can we use object properties and methods in an array
Asked
Active
Viewed 41 times
0
-
`arr.push()` is using an array method. `arr.length` is an array property. You *could* add your own methods and properties but most of the time it's a bad idea. – VLAZ May 04 '21 at 14:55
-
Yes. Indeed, arrays are objects, so you can do `[1, 2, 3].length` (property) and get `3`, or `[1, 2, 3].push(4)` (method) and update your array – GusSL May 04 '21 at 14:56
-
2What is your actual question? What are you trying to do? – Alon Eitan May 04 '21 at 14:57
-
[JavaScript “Associative Arrays” Considered Harmful](https://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/) – VLAZ May 04 '21 at 15:00
1 Answers
0
Indeed an Array
is a particular type of object:
const arr = [];
console.log(typeof arr); // object
console.log(arr instanceof Array); // true (This particular object is an instance of Array)
console.log(typeof arr.push); // function (Array method)
console.log(typeof arr.length); // number (Array property)

Guerric P
- 30,447
- 6
- 48
- 86