0

I have a request forming using the JSON Object something like this:

let formData = {
    name: classifierName,
    fire_positive_examples: {
        value: decodedPositiveExample,
        options: {
            filename: 'positive.zip'
        }
    },
    negative_examples: {
        value: decodedNegativeExample,
        options: {
            filename: 'negative.zip'
        }
    }
};

I want to inject a dynamic value from String instead of fire_positive_examples.

When trying to append a String, something like let classNamePositive = className + '_positive_examples'; and have classNamePositive instead of fire_positive_examples, it instead has dynamic value it injects classNamePositive.

1 Answer 1

1

Two ways:

let formData = {
  name: classifierName
}
formData[classNamePositive] = ...

or

let formData = {
  name: classifierName,
  [classNamePositive]: ...
}
Sign up to request clarification or add additional context in comments.

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.