I have an array of objects like this:
myArray = [
{itemOneKey: 'itemOneValue', itemTwoKey: 'itemTwoValue'},
{itemThreeKey: 'itemThreeValue'}
];
I wish to turn it to a single object like this:
myObject = {
itemOneKey: 'itemOneValue',
itemTwoKey: 'itemTwoValue',
itemThreeKey: 'itemThreeValue'
}
in TypeScript. Anyone have a clue how I can go about to achieve this?
You can use Object.assign
with spread syntax to merge all the objects.
const myArray = [
{itemOneKey: 'itemOneValue', itemTwoKey: 'itemTwoValue'},
{itemThreeKey: 'itemThreeValue'}
];
const res = Object.assign({}, ...myArray);
console.log(res);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments