var i; for (i = 0; i < fruits.length; i += 1) { if (fruits[i] == "pear") { fruits.splice(i, 1); i -= 1; } }
6.4. Listing
Because JavaScript arrays are really objects, the for in operator can be used to iterate over all the properties of the array. Unfortunately, for in makes no guarantees about the order of properties, and most arrays expect elements to be created in numerical order. In addition, there is still a problem with unexpected properties being unloaded from the prototype circuit.
Fortunately, the usual approval problem resolves these issues. JavaScript for the operator is similar to that in most C-like languages. It is controlled by three sentences: the first initializes the loop, the second is the while condition, and the third is incremented:
var i; for (i = 0; i < myArray.length; i += 1) { document.writeln(myArray[i]); }
user278064
source share