Here a code as an example:
const nums = [1, 1, 3, 2, 2, 2, 2, 2, 2, 2];
oddArr = arrNum.filter(function(num,index){
return num % 2 != 0
})
evenArr = arrNum.filter(function(num,index){
return num % 2 === 0
})
Here I would like to return the new array with the original index of each element that meet the condition. I tried placing a , after the condition (num % 2 === 0) but nothing
In case of looking for odds number, I would like to get an output like this (bold data refers to the index of that number in the original array: [1,0,1,1,3,2] Maybe get an object for each result would be better. Something like this:
[
{1,0},
{1,1},
{3,2}
]
I dont even know if its possible,but I wonder because this other code effectively works:
function array_odd_even_position(a) {
return a.filter((num,index) => console.log(num,index));
}
array_odd_even_position([1, 1, 3, 2, 2, 2, 2, 2, 2, 2])