GetNthElement method (NotesJSONArray - LotusScript)

Returns the JSON element at a specified position in an array.

Defined in

NotesJSONArray

Syntax

Set el = jsarray.GetNthElement(Index)

Parameters

Index

Long

1-based index that identifies which element to return.

[SuppressErrors]

Boolean. Optional. If True, suppress error “Index is out of range” and return Null element when the index is bigger than max element index of NOTESJSON Array.
Note: This parameter is new with release 14.5.1.

Return value

Returns nth NotesJSONElement in the array. If not use SuppressError = True, will raise “Index is out of range” error when pass in Index bigger than max element index of NotesJSON Array.

Example

The following code displays a message box with the value 4.
Dim s As New NotesSession
Dim jsnav As NotesJSONNavigator
Dim el As NotesJSONElement
Dim arr As NotesJSONArray

Set jsnav = s.CreateJSONNavigator(|{"numbers:" : [1,2,3,4,5]}|)
Set el = jsnav.GetFirstElement()
Set arr = el.value
Set el = arr.GetnthElement(4)
MsgBox "Nth element: " & CStr(el.Value)
The following code return Null element and not raise error when pass in Index bigger than Array Size.
Dim s As New NotesSession
Dim jsnav As NotesJSONNavigator
Dim el As NotesJSONElement
Dim arr As NotesJSONArray
	
Set jsnav = s.CreateJSONNavigator(|{"numbers:" : [1,2,3,4,5]}|)
Set el = jsnav.GetFirstElement()
Set arr = el.value
Set el = arr.GetnthElement(6, True) 'Suppress index out of range Error
If el Is Nothing Then
	MessageBox("Index out of range")
End If