Tell us what’s happening:
Describe your issue in detail here.
I am badly stuck here - tried to follow solution on other forum posts but cannot figure out how I can do this without using indexOf. Any help will be much appreciated please!
**Your code so far**
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for(let i = 0; i<arr.length;i++){
let k = 0;
let p = 0;
for (let j = 0;j<arr[i].length;j++){
if (arr[i][j] == elem){
newArr = [];
k++;
}
else {
if (k>0){
newArr=[];
}
else {
p++;
}
}
}
// Only change code above this line
return newArr;
}
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [3, 13, 26], [19, 2, 9]], 3))
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.109 Safari/537.36
Challenge: Iterate Through All an Array’s Items Using For Loops
function filteredArray(arr, elem) {
let newArr = [];
// Only change code below this line
for(let i = 0; i<arr.length;i++){
let match = 0;
for (let j = 0;j<arr[i].length;j++){
if (arr[i][j] == elem){
match++;
break;
}
}
if (match == 0){
newArr.push(arr[i])
}
}
// Only change code above this line
return newArr;
}
console.log(filteredArray([[3, 2, 3], [1, 6, 3], [2, 13, 26], [19, 2, 9]], 3))```
Being this is an educational forum, it is frowned upon to just give you an answer. That is why I offered a way to figure it out without just giving you the code to make it work. People learn better that way.