remove an item from an array

   // delete an item from the array
    function remove(arr, item) {
	  if (arr.length) { //Continue to judge whether the array has a value or not
	    var index = arr.indexOf(item); // Get the index of the value to be deleted and assign it to index
		if (index > -1) { // if the entered value exists Note: the value not found in the array is -1
		  arr.splice(index, 1); // then delete the input value
		}
	  }
	}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324970830&siteId=291194637