JavaScriptKit Documentation

Class JSArray

public class JSArray: JSBridgedClass  

A wrapper around the JavaScript Array class that exposes its properties in a type-safe and Swifty way.

%157 JSArray JSArray RandomAccessCollection RandomAccessCollection JSArray->RandomAccessCollection JSBridgedClass JSBridgedClass JSArray->JSBridgedClass

Nested Types

JSArray.Iterator

Iterator type for JSArray, conforming to IteratorProtocol from the standard library, which allows easy iteration over elements of JSArray instances.

Conforms To

JSBridgedClass

Conform to this protocol when your Swift class wraps a JavaScript class.

RandomAccessCollection

Nested Type Aliases

Element

public typealias Element = JSValue

Initializers

init?(from:​)

public required convenience init?(from value: JSValue)  

init?(_:​)

public convenience init?(_ jsObject: JSObject)  

Construct a JSArray from Array JSObject. Return nil if the object is not an Array.

Parameters

object

A JSObject expected to be a JavaScript Array

init(unsafely​Wrapping:​)

public required init(unsafelyWrapping jsObject: JSObject)  

Properties

constructor

public static let constructor = JSObject.global.Array.function

js​Object

public let jsObject: JSObject

start​Index

public var startIndex: Int  

end​Index

public var endIndex: Int  

length

public var length: Int  

The number of elements in that array including empty hole. Note that length respects JavaScript's Array.prototype.length

e.g.

const array = [1, , 3];
let array: JSArray = ...
array.length // 3
array.count  // 2

count

public var count: Int  

The number of elements in that array not including empty hole. Note that count syncs with the number that Iterator can iterate. See also: JSArray.length

Methods

make​Iterator()

public func makeIterator() -> Iterator