I have defined an array like so :
var myArray = {myNewArray: ['string1' , 'string2' , 'string3']};
I want to iterate over the array and delete an element that matches a particular string value. Is there a clean way in jQuery/javascript to achieve this ?
Or do I need to iterate over each element, check its value and if its value matches the string im comparing, get its id and then use that id to delete from the array ?
JavaScript arrays have an
indexOfmethod that can be used to find an element, thensplicecan be used to remove it. For example:After that code executes,
myNewArrayis['A', 'C'].