All Downloads are FREE. Search and download functionalities are using the official Maven repository.

testsrc.doctests.arrays.doctest Maven / Gradle / Ivy

Go to download

A distribution of rhino which releases snapshots from a submodule folder containing forked sources.

The newest version!
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

js> [1,2,undefined,4].join(';')
1;2;;4
js> [1,2,null,4].join(';')
1;2;;4
js> var arr = []; arr[0] = 1; arr[1] = 2; arr[3] = 4; arr.join(';')
1;2;;4
js> var arr = [1,2,3,4]; delete arr[2]; arr.join(';')
1;2;;4

js> var arr = ["a","b","c","d"];
js> var _ = arr.length = 2; 
js> arr[2] === undefined
true
js> arr[1] === "b"
true

js> [1,2,3].reverse().toSource()
[3, 2, 1]

js> [2,1,3].sort().toSource()
[1, 2, 3]

js> var arr = [1,2,3]; arr.push(4); arr.toSource()
[1, 2, 3, 4]

js> var arr = [1,2,3]; arr.pop(); 
3
js> arr.toSource()
[1, 2]

js> var arr = [1,2,3]; arr.shift();
1
js> arr.toSource()
[2, 3]

js> var arr = [2,3]; arr.unshift(1); arr.toSource()
[1, 2, 3]

js> var arr = [1,2,3]; arr.splice(1, 1, "a", "b").toSource()
[2]
js> arr.toSource()
[1, "a", "b", 3]

js> [1,2,3].concat([4,5,6]).toSource()
[1, 2, 3, 4, 5, 6]

js> [1,2,3].indexOf(2)
1




© 2015 - 2024 Weber Informatics LLC | Privacy Policy