0

Can the following 5 lines be condensed into a single line array?

var exmplArray = [];
exmplArray['hours'] = 0;
exmplArray['overtime'] = 0;
exmplArray['income'] = 0;
exmplArray['expenditure'] = 0;

I have tried the following but an error kicks in: 'Uncaught ReferenceError: Invalid left-hand side in assignment'

var exmplArray = ['hours' = 0, 'overtime' = 0, 'income' = 0, 'expenditure' = 0];

any ideas?

2 Answers 2

1

You should use object {} instead when you need a "hash" in javascript:

var example = {};
example['hours'] = 0;
example['overtime'] = 0;
example['income'] = 0;
example['expenditure'] = 0;

or

// the quote could be ommitted.
var example = { 'hours': 0, 'overtime': 0, 'income': 0, 'expenditure': 0 };
Sign up to request clarification or add additional context in comments.

Comments

0

try

var exmplArray = {'hours' :0, 'overtime' :0, 'income' :0, 'expenditure' :0};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.