public interface JSArrayFunctions extends JSObjectFunctions
hasOwnProperty| Modifier and Type | Method and Description |
|---|---|
JSArray |
concat(JSArray args)
function concat(args) creates and returns a new array that is the result of concatenating each
of its arguments to an array.
|
JSString |
join(java.lang.String separator)
function join(separator) converts each element of the array into a string.
|
JSObject |
pop()
function pop() removes and returns the last element of an array.
|
void |
push(JSArray array)
function push(args) append elements to an array.
|
JSArray |
reverse()
function reverse() reverse the elements of an array.
|
JSObject |
shift()
function shift() shift array elements down.
|
JSArray |
slice(java.lang.Number start,
java.lang.Number end)
function slice(start, end) return a portion of an array
|
JSArray |
sort(JSFunction function)
function sort(function) sort the elements of an array
|
JSArray |
splice(JSNumber start,
JSNumber deletecount,
JSArray items)
function splice(start, deletecount, items) insert, remove, or replace array elements
|
JSNumber |
unshift(JSArray value)
function unshift(items) insert elements at the beginning of an array
|
hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString, toString, valueOfJSArray concat(JSArray args)
Example
var c = [1,2,3]; c.concat(4,5); //Returns [1,2,3,4,5] c.concat([4,5]); //Returns [1,2,3,4,5] c.concat(4,[5,[6, 7]]); //Returns [1,2,3,4,5, [6,7]]
args - Any number of values to be concatenated to an array.ArrayJSString join(java.lang.String separator)
Example
var a = [1,2,3];
var s = a.join("|"); //s is the string "1|2|3"
separator - An optional character or string used to separate each element with the string.ArrayJSObject pop()
Example
var stack = [1,2,3]; stack.pop(); // returns 3, stack [1, 2] stack.pop(); // returns 2, stack [1] stack.pop(); // returns 1, stack []
void push(JSArray array)
Example
var vals = []; vals.push(1,2,3); // returns new array [1,2,3]
JSArray reverse()
Example
var r = [1,2,3]; r.reverse(); // r is now [3,2,1]
ArrayJSObject shift()
Example
var s = [1,2,3]; s.shift(); // Returns 1; s = [2,3] s.shift(); // Returns 2; s = [3]
JSArray slice(java.lang.Number start, java.lang.Number end)
Example
var s = [1,2,3,4,5]; s.slice(0,3); // Returns [1,2,3] s.slice(3); // Returns [4,5] s.slice(1,-1); // Returns [2,3,4]
start - The array index from where to begin. If negative, this argument specifies a position measured from the end of the array.end - The array index immediately after the end of the slice. If not specified then the slice includes all the array elements from the start to the end of the array.Array,
splice();JSArray sort(JSFunction function)
Example
function numbersort(a,b) {return a-b;}
var s = new Array(22,1111,33,4,55]);
s.sort(); //Alphabetical order : 1111,22,33,4,55
s.sort(numbersort); //Numerical order : 4, 22, 33, 55, 1111
function - an optional function used to specify the sorting orderArrayJSArray splice(JSNumber start, JSNumber deletecount, JSArray items)
Example
var s = [1,2,3,4,5,6,7,8]; s.splice(1,2); //Returns [2,3]; s is [1,4] s.splice(1,1); //Returns [4]; s is [1] s.splice(1,0,2,3); //Returns []; s is [1 2 3]
start - the array element at which the insertion and/or deletion is to begindeletecount - The number of elements starting with and including start.items - zero or more items to be inserted into the arrayArray,
shift();