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]
}afterpositiveArr.push(item)for (const item of t) { … }for the loop so that you don't get confused by the closing})offorEach