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.

%35 JSArray JSArray JSBridgedClass JSBridgedClass JSArray->JSBridgedClass RandomAccessCollection RandomAccessCollection JSArray->RandomAccessCollection

Nested Types

JSArray.Iterator

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