Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Const array using data from two objects in TypeScript

I require some help on this particular issue I’m encountering, I’m trying to const an array using two objects with Object.keys(...).map and &&.

Code:

const plugins: PluginManifest[] = Object.values(window.Aliucord.pluginManager.plugins).map((p) => p.manifest) && Object.values(window.Aliucord.pluginManager.disabledPlugins).map(p => p);

The above code uses the data only from the disabledPlugins Object.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Am I doing something wrong or is there a better way to do this?

>Solution :

In this case I would expect && to simply be resolving to the second part of its expression. && certainly doesn’t combine arrays. But you can combine them into one array by spreading them into an array literal. For example:

const firstArray = [1,2,3];
const secondArray = [4,5,6];
const finalArray = [...firstArray, ...secondArray];
console.log(finalArray);

So in your case, since those .map() operations produce arrays, you can spread them into another array:

const plugins: PluginManifest[] = [
  ...Object.values(window.Aliucord.pluginManager.plugins).map((p) => p.manifest),
  ...Object.values(window.Aliucord.pluginManager.disabledPlugins).map(p => p)
];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading