I am trying to separate positive and negative numbers in an array using Javascript. But the code Iam trying to use is not working. Jere is the code I was trying to use which I got from Separate negative and positive numbers in array with javascript
var t = [-1,-2,-3,5,6,1]
var positiveArr = [];
var negativeArr = [];
t.forEach(function(item){
if(item<0){
negativeArr.push(item);
}
else{
positiveArr.push(item)
})
console.log(positiveArr) // should output [5, 6, 1]
console.log(negativeArr) // should output [-1, -2, -3]