1

I am trying to create an array of objects like below as expected by dojo store

[
    { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
    { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
    { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
    ...
]

The array part is simple, but how do I dynamically create the object keys part? "Column 1" etc ?

2 Answers 2

4

Just to give an idea,

You can access an object attribute using associative array subscript like this:

var a = {}
a["col 1"] = "some value";
Sign up to request clarification or add additional context in comments.

Comments

0
var myArr = [
  { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
  { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
  { "Column 1": "Value ...", "Column 2": "Value ...", "Column 2": "Value ...", ... },
]

var obj = {};
    obj['your_key'] = 'some value';
    obj['your_another_key'] = 'some other value';
    ...

myArr.push(obj);

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.