Filtering an array from another array. What might be going wrong? "num.push(arr[i]);" not displaying any value

// Challenge
//1. Create an array(arr) with the numbers 1 to 10
//2. Create a filter that pushes the numbers from 4 to 9 to a new array(num)

// Solution

let  const arr = [1,2,3,4,5,6,7,8,9,10];
let  const num = [ ];
for (let i=0; i < arr.length; i++) {
  if(arr[i] >= 4 && arr[i] <= 9) {

It really helps if the post contains your questions.

Does this challenge want you to use the filter method? If so, it is teaching an anti-pattern. You shouldn’t push to an external array with a filter. You directly create a new array from the old one.

Yea the question is the one right above the solution in the post.

I mean, it helps if you put your question, you specific part you need help with, in tme text of the post instead of the title.

Anyway, are they looking for you to use the filter method?

Ok I understand you now. I think the function “num.push(arr[i]);” in my solution is refusing to display.

Well can’t really tell but that is the question.

Yea I think i got it now. I only needed the display command - console.log(num); to show the “num” array content.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.