1

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.

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

1 Answer 1

2

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)
];
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.