8

I am attempting to add a variable key, with no luck.

Here's what I got so far:

mysql('translations',{
    check: 'element_id',
    element_id: element_id,
    {'lang-'+lang_id}: value
});

The variable key is the last line of the function.

Any ideas?

0

2 Answers 2

19

You can't use expressions for the identifiers in an object literal.

First create the object, then you can use dynamic names:

var obj = {
  check: 'element_id',
  element_id: element_id,
}

obj['lang-'+lang_id] = value;

mysql('translations', obj);
Sign up to request clarification or add additional context in comments.

1 Comment

Yes I was thinking of doing something like this. Thank you!
1

You can do this:

var x = {
    check: 'element_id',
    element_id: element_id    
};
x['lang-'+lang_id] = value;

mysql('translations', x);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.