[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
| Name | Type | Description |
|---|---|---|
imp? | object | Internal implementation object |
Example
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
| Name | Type | Description |
|---|---|---|
| Val | number | integer value |
Returns
void
Example
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
| Name | Type | Description |
|---|---|---|
| Index | number | array index |
Returns
number
Return element value
Example
import { McGeLongArray } from "mxcad"
const array = new McGeLongArray();
array.append(5);
array.append(10);
console.log(array.at(0)); //Output: 5
console.log(array.at(1)); //Output: 10clear
▸ clear(): void
Clear the array
Returns
void
Example
//Array is an integer array
array.clear()copy
▸ copy(val): McGeLongArray
Copy the value of the object
Parameters
| Name | Type | Description |
|---|---|---|
| Val | [McGeLongArray] (2d. McGeLongArray. md) | Integer array |
Returns
Example
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
| Name | Type | Description |
|---|---|---|
| AryId | [McObject Id] (2d. McObject Id. md) [] | McObject Id array |
Returns
Example
//ObjectIdArray is an array of object IDs
const array = new McGeLongArray();
array.copyFormAryId(objectIdArray);forEach
▸ forEach(call): void
iterate through an array
Parameters
| Name | Type | Description |
|---|---|---|
| Call | (val: number, index: number)=>void | callback function |
Returns
void
Example
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 10length
▸ length(): number
Return the length of the array
Returns
number
array length
Example
import { McGeLongArray } from "mxcad"
const array = new McGeLongArray();
console.log(array.length()); //Output: 0setAt
▸ setAt(index, val): void
Set the value of data elements through array indexing
Parameters
| Name | Type | Description |
|---|---|---|
| Index | number | array index value |
| Val | number | integer numerical value |
Returns
void
Example
import { McGeLongArray } from "mxcad"
const array = new McGeLongArray();
array.append(5);
array.append(10);
array.setAt(0, 15);
console.log(array.at(0)); //Output: 15