I've tried looking to see if this is possible, but I can't find my answer.
I'm trying to get the following to work:
var defaults = {
'background-color': '#000',
color: '#fff',
weekdays: {['sun','mon','tue','wed','thu','fri','sat']}
};
It just gives an error, and I've tried using ({...})
and [{...}]
I'd like to be able to access the weekdays using something like:
defaults.weekdays[0];
is this possible?
This question is related to
javascript
In regards to multiple arrays in an object. For instance, you want to record modules for different courses
var course = {
InfoTech:["Information Systems","Internet Programming","Software Eng"],
BusComm:["Commercial Law","Accounting","Financial Mng"],
Tourism:["Travel Destination","Travel Services","Customer Mng"]
};
console.log(course.Tourism[1]);
console.log(course.BusComm);
console.log(course.InfoTech);
var obj = {
webSiteName: 'StackOverFlow',
find: 'anything',
onDays: ['sun' // Object "obj" contains array "onDays"
,'mon',
'tue',
'wed',
'thu',
'fri',
'sat',
{name : "jack", age : 34},
// array "onDays"contains array object "manyNames"
{manyNames : ["Narayan", "Payal", "Suraj"]}, //
]
};
var defaults = {_x000D_
_x000D_
"background-color": "#000",_x000D_
color: "#fff",_x000D_
weekdays: [_x000D_
{0: 'sun'},_x000D_
{1: 'mon'},_x000D_
{2: 'tue'},_x000D_
{3: 'wed'},_x000D_
{4: 'thu'},_x000D_
{5: 'fri'},_x000D_
{6: 'sat'}_x000D_
]_x000D_
_x000D_
};_x000D_
_x000D_
console.log(defaults.weekdays[3]);
_x000D_
// define
var foo = {
bar: ['foo', 'bar', 'baz']
};
// access
foo.bar[2]; // will give you 'baz'
var data = {_x000D_
name: "Ankit",_x000D_
age: 24,_x000D_
workingDay: ["Mon", "Tue", "Wed", "Thu", "Fri"]_x000D_
};_x000D_
_x000D_
for (const key in data) {_x000D_
if (data.hasOwnProperty(key)) {_x000D_
const element = data[key];_x000D_
console.log(key+": ", element);_x000D_
}_x000D_
}
_x000D_
Source: Stackoverflow.com