Jump to content

removing a specific element in an array


hAnDoFhOnOr

Recommended Posts

i know that you can use the splice() function to remove elements in an array by specifying the index of the element you want to remove. my question is what if you do not know the index but know the specific element you want to remove.e.g. array animal = new Array ("cat, dog, mouse, rat, cow");if you want to remove the element mouse, you can do animal.splice(2,0) right?but what if i don't know the index, is there a javascript function that lets you search for a specific element index. Does array.indexOf(array_element) work in javascript? thanks.

Link to comment
Share on other sites

i have seen that page already, as i've said i know i can use the splice() function but i need something that can determine the index of a specific element in an array. I have been trying to usevar arr_index = array.indexOf(array_element); so that i can use array.splice(arr_index, 0); to remove the element. But it doesn't seem to work, any thoughts? I'll appreciate it very much.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...