How to separate even and odds numbers from an array

Hello everyone!
I am dealing with this exercise, and I am stuck.
I have to separate from an array even and odd.
const numbers = [1, 2, 3, 4, 5, 6];

//has to return { even: [2, 4, 6], odd: [1, 3, 5] }

function separateArray(array) {
//the code goes here
I already try several options with no luck at all. I would be appreciate any help or suggestion to solve it. Thanks!

Try this:

const numbers = [1,2,3,4,5,6];

function seperateArray(array) {

const odd = array.filter(num => num % 2 === 1);

const even = array.filter(num => num % 2 === 0);

return { odd: odd, even: even }



This works by using the modulo ‘%’ sign which returns the remainder after dividing a number. So in this case, all odd numbers divided by 2 would return a remainder of 1 and all even numbers would return 0. I also use the .filter() iterator function which iterates through each element in an array and filters out those elements that do not meet the conditions set inside the function. The original array is not changed but instead, the new array is assigned to the variable it was initialized to.

It worked!!! thank you so much for your help!