Working with javascript arrays

Hello there, I just started learning Javascript.
I am trying to solve my first puzzle, would appreciate any help.

I have an array of names and variable for one of the names from the array. I need to print out the entire array without that particular name (Irene). What would be the best way to do that?

function myFunction (names, nameNotForPrint) {
           var names = ["John", "Peter", "Marry", "Irene", "Patrick", "Ema"];
           var nameNotForPrint = names[3];

Thank you!

Instead, let me ask you a question, what have you tried to do? What is your code? There is any method or statement or loop that you think can work?

1 Like

Hi camper , you can use splice method
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements.

names.splice(3,1); // here means go to index 3 in the names array and delete 1 item 

this method does mutate (change) the original names array
now if you go and print names on the console you would find names is printed without the desired item to be removed

Wrote a psuedo code how I would think about it in a simple way, it’s good if you try and solve it yourself :slight_smile:

Loop the array
  if index equals "Irene" continue loop
  console.log the index.