Languages
[Edit]
EN

JavaScript - create more complex objects e.g. object of objects

1 points
Created by:
telsa
502

Create object with array of strings (columns) and array of objects (users). Each user is described by id, name, age properties.

// ONLINE-RUNNER:browser;

var advObj = {
    columns: ['ID', 'Name', 'Age'],
    users: [
		{ id: 1, name: 'Bob', age: 25 },
		{ id: 2, name: 'Adam', age: 43 },
		{ id: 3, name: 'Mark', age: 16 },
		{ id: 4, name: 'John', age: 29 }
	]
};

console.log(advObj.columns);
console.log('--------');
for (let user of advObj.users) {
    console.log(user.id + ', ' + user.name + ', ' + user.age);
}

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join