I had a question I just couldn't find the answer to. Say I have something like the following:
var test = [{"a": "1", "b": "2", "c": "3", "d": "4"}];
Now, say I wanted this test array to have an additional value based on some predetermined condition. I could do this:
if(cond) {
var test = [{..., "cond": true}];
}
else {
var test = [{...}];
}
In essence, I want the array key to exist if the condition holds.
I tried the following so far:
test[0]["cond"] = true; // (similar to how php does it, I thought)
test[0].push("cond":true");
But they did not quite work as I intended (or at all). How would I achieve the above? It would avoid a lot of code duplication.