Skip to content
On this page

[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/McGeLongArray

Class: McGeLongArray

2d.McGeLongArray

Integer array

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new McGeLongArray(imp?)

Constructor.

Parameters

NameTypeDescription
imp?` ObjectInternal implementation object

Example

ts
import { McGeLongArray } from "mxcad"

//Create a new instance of McGeLongArray
 const myArray = new McGeLongArray();

//Initialize McGeLongArray by passing in an object
 const initialValues = { data: [1, 2, 3, 4] };
 const myArray2 = new McGeLongArray(initialValues);

Properties

imp

imp: any

Internal implementation object

Methods

append

append(val): void

Add a value to an array

Parameters

NameTypeDescription
Valnumberinteger value

Returns

void

Example

ts
import { McGeLongArray } from "mxcad";

  const array = new McGeLongArray();
  array.append(5);
  array.append(10)

at

at(index): number

Obtain the values of data elements based on the array index

Parameters

NameTypeDescription
Indexnumberarray index

Returns

number

Return element value

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

console.log(array.at(0)); //  Output: five
console.log(array.at(1)); //  Output: ten

clear

clear(): void

Clear the array

Returns

void

Example

ts
//Array is an integer array
array.clear()

copy

copy(val): McGeLongArray

Copy the value of the object

Parameters

NameTypeDescription
Val[McGeLongArray] (2d. McGeLongArray. md)Integer array

Returns

McGeLongArray

Example

ts
import { McGeLongArray } from "mxcad"

  const array1 = new McGeLongArray();
  const array2 = new McGeLongArray();
  array2.append(10);
  array2.append(20);

//Copy the value of array2 to array1
  array1.copy(array2);

copyFormAryId

copyFormAryId(aryId): McGeLongArray

Copy values from the McObjectid array

Parameters

NameTypeDescription
AryId[McObject Id] (2d. McObject Id. md) []McObject Id array

Returns

McGeLongArray

Example

ts
//ObjectIdArray is an array of object IDs
  const array = new McGeLongArray();
  array.copyFormAryId(objectIdArray);

forEach

forEach(call): void

Traverse the array

Parameters

NameTypeDescription
Call(val: number, index: number)=>voidcallback function

Returns

void

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

  array.forEach((val, index) => {
    console.log(`Index ${index}: Value ${val}`);
  });
//Output:
  // Index 0: Value 5
  // Index 1: Value 10

length

length(): number

Return the length of the array

Returns

number

Array length

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
console.log(array.length()); //  Output: 0

setAt

setAt(index, val): void

Set the value of data elements through array indexing

Parameters

NameTypeDescription
Indexnumberarray index value
Valnumberinteger numerical value

Returns

void

Example

ts
import { McGeLongArray } from "mxcad"

  const array = new McGeLongArray();
  array.append(5);
  array.append(10);

  array.setAt(0, 15);
console.log(array.at(0)); //  Output: fifteen