0

Say i have this object:

const element = {
    name: 'first_name',
    value: 'Joe Blow',
}

how do i use element.name as the key and element.value to construct another object?

for example, i've tried this:

const data = {
    element.name: element.value,
}

above example does not work.

0

1 Answer 1

0

got it using es6 computed properties:

const data = {
    [element.name]: element.value,
}
Sign up to request clarification or add additional context in comments.

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.