⊗jsOpBsAOO 21 of 60 menu

Arrays of Objects in OOP in JavaScript

Class objects can be stored in an array and various operations can be performed on them, just like on array elements. Let's look at an example. Let's say we have the following class:

class User { #name; constructor(name) { this.#name = name; } getName() { return this.#name; } }

Let's make an array of objects of this class:

let users = [ new User('john'), new User('eric'), new User('kyle'), ];

Let's loop through this array and print out the name of each user:

for (let user of users) { console.log(user.getName()); }

Make an array of class objects Employee.

Loop through the created array and display the names and salaries of each employee.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline