There are several functions to perform operations on arrays.
The best place to look at the JavaScriptUtil API documentation, that have a complete list of functions. Here, the idea is not to replicate that information, but to give a basic understanding.
The indexOf, inArray and arrayEquals functions tests elements and arrays;
Examples:var letters = ["a", "b", "c", "d"]; indexOf("b") -> 1 indexOf("x") -> -1 inArray("b", letters) -> true arrayEquals(letters, ["a", "b"]) -> false arrayEquals(letters, ["a", "b", "c", "d"]) -> true
The arrayConcat and removeFromArray functions return new arrays based on other arrays, by adding and removing elements.
Examples:var letters = ["a", "b", "c", "d"]; arrayConcat(letters, "e", ["f", "g"]) -> ["a", "b", "c", "d", "e", "f", "g"] removeFromArray(letters, "b") -> ["a", "c", "d"] removeFromArray(letters, "a", "c") -> ["b", "d"]
Previous: Working with objects |
Table of Contents | Next: Working with dates |