Reputation:
I'm trying to push key + value into the array with their unique values.
Trying like this:
for (const [key, value] of Object.entries(check)) {
console.log(`${key}: ${value}`);
this.inputFields.push({
//`${key}' : '${value}`
})
}
Console.log output give me the correct values:
Username: ''
Password: ''
What i want to do is to push into inputFields the key and value so input fields will be:
Username:
Password:
Without the need of hardcode it into it, because every object in my array have different key and values.
Upvotes: 0
Views: 1192
Reputation: 1
You could use []
to wrap the computed key :
for (const [key, value] of Object.entries(check)) {
console.log(`${key}: ${value}`);
this.inputFields.push({
[key]:value
})
}
Upvotes: 2