1# ArkTS使用JSVM-API接口进行array相关开发 2 3### 介绍 4 5使用 JSVM-API 接口进行数组(array)相关开发时,调用相关接口可以在 JSVM 模块中直接操作和处理 JavaScript 中的数组。 6 7该工程中展示的代码详细描述可查如下链接: 8 9- [使用JSVM-API接口进行array相关开发](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/napi/use-jsvm-about-array.md) 10 11### 效果预览 12 13| 首页 | 执行及结果即时反馈 | 14| :----------------------------------------------------------------: | :----------------------------------------------------------------: | 15| <img src="./screenshots/JsvmAboutArray_1.png" style="zoom:33%;" /> | <img src="./screenshots/JsvmAboutArray_2.png" style="zoom:33%;" /> | 16 17### 使用说明 18 191. 在主界面,可以点击Hello World,开始执行。 202. 执行结果会即时反馈在屏幕中央,并在控制台打印log。 21 22### 工程目录 23 24``` 25createarray/src/ 26 ├── main 27 │ ├── cpp 28 │ │ ├── types 29 │ │ │ ├── libentry 30 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 31 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 32 │ │ ├── CMakeLists.txt // 配置CMake打包参数 33 │ │ ├── hello.cpp // 实现Native侧的runTest接口 34 │ ├── ets 35 │ │ ├── entryability 36 │ │ ├── entrybackupability 37 │ │ ├── pages 38 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 39 │ ├── module.json5 40 │ └── resources 41 ├── ohosTest 42 │ ├── ets 43 │ │ ├── test 44 │ │ ├── Ability.test.ets // 自动化测试代码 45createarraywithlength/src/ 46 ├── main 47 │ ├── cpp 48 │ │ ├── types 49 │ │ │ ├── libcreatearraywithlength 50 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 51 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关联 52 │ │ ├── CMakeLists.txt // 配置CMake打包参数 53 │ │ ├── hello.cpp // 实现Native侧的runTest接口 54 │ ├── ets 55 │ │ ├── createarraywithlengthability 56 │ │ ├── pages 57 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 58 │ ├── module.json5 59 │ └── resources 60 ├── ohosTest 61 │ ├── ets 62 │ │ ├── test 63 │ │ ├── Ability.test.ets // 自动化测试代码 64createdataview/src/ 65 ├── main 66 │ ├── cpp 67 │ │ ├── types 68 │ │ │ ├── libcreatedataview 69 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 70 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 71 │ │ ├── CMakeLists.txt // 配置CMake打包参数 72 │ │ ├── hello.cpp // 实现Native侧的runTest接 73 │ ├── ets 74 │ │ ├── createdataviewability 75 │ │ ├── pages 76 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 77 │ ├── module.json5 78 │ └── resources 79 ├── ohosTest 80 │ ├── ets 81 │ │ ├── test 82 │ │ ├── Ability.test.ets // 自动化测试代码 83createtypedarray/src/ 84 ├── main 85 │ ├── cpp 86 │ │ ├── types 87 │ │ │ ├── libcreatetypedarray 88 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 89 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 90 │ │ ├── CMakeLists.txt // 配置CMake打包参数 91 │ │ ├── hello.cpp // 实现Native侧的runTest接 92 │ ├── ets 93 │ │ ├── createtypedarrayability 94 │ │ ├── pages 95 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 96 │ ├── module.json5 97 │ └── resources 98 ├── ohosTest 99 │ ├── ets 100 │ │ ├── test 101 │ │ ├── Ability.test.ets // 自动化测试代码 102deleteelement/src/ 103 ├── main 104 │ ├── cpp 105 │ │ ├── types 106 │ │ │ ├── libdeleteelement 107 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 108 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 109 │ │ ├── CMakeLists.txt // 配置CMake打包参数 110 │ │ ├── hello.cpp // 实现Native侧的runTest接 111 │ ├── ets 112 │ │ ├── deleteelementability 113 │ │ ├── pages 114 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 115 │ ├── module.json5 116 │ └── resources 117 ├── ohosTest 118 │ ├── ets 119 │ │ ├── test 120 │ │ ├── Ability.test.ets // 自动化测试代码 121getarraylength/src/ 122 ├── main 123 │ ├── cpp 124 │ │ ├── types 125 │ │ │ ├── libgetarraylength 126 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 127 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 128 │ │ ├── CMakeLists.txt // 配置CMake打包参数 129 │ │ ├── hello.cpp // 实现Native侧的runTest接 130 │ ├── ets 131 │ │ ├── getarraylengthability 132 │ │ ├── pages 133 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 134 │ ├── module.json5 135 │ └── resources 136 ├── ohosTest 137 │ ├── ets 138 │ │ ├── test 139 │ │ ├── Ability.test.ets // 自动化测试代码 140getdataviewinfo/src/ 141 ├── main 142 │ ├── cpp 143 │ │ ├── types 144 │ │ │ ├── libgetdataviewinfo 145 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 146 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 147 │ │ ├── CMakeLists.txt // 配置CMake打包参数 148 │ │ ├── hello.cpp // 实现Native侧的runTest接 149 │ ├── ets 150 │ │ ├── getdataviewinfoability 151 │ │ ├── pages 152 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 153 │ ├── module.json5 154 │ └── resources 155 ├── ohosTest 156 │ ├── ets 157 │ │ ├── test 158 │ │ ├── Ability.test.ets // 自动化测试代码 159getelement/src/ 160 ├── main 161 │ ├── cpp 162 │ │ ├── types 163 │ │ │ ├── libgetelement 164 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 165 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 166 │ │ ├── CMakeLists.txt // 配置CMake打包参数 167 │ │ ├── hello.cpp // 实现Native侧的runTest接 168 │ ├── ets 169 │ │ ├── getelementability 170 │ │ ├── pages 171 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 172 │ ├── module.json5 173 │ └── resources 174 ├── ohosTest 175 │ ├── ets 176 │ │ ├── test 177 │ │ ├── Ability.test.ets // 自动化测试代码 178gettypedarrayinfo/src/ 179 ├── main 180 │ ├── cpp 181 │ │ ├── types 182 │ │ │ ├── libgettypedarrayinfo 183 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 184 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 185 │ │ ├── CMakeLists.txt // 配置CMake打包参数 186 │ │ ├── hello.cpp // 实现Native侧的runTest接 187 │ ├── ets 188 │ │ ├── gettypedarrayinfoability 189 │ │ ├── pages 190 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 191 │ ├── module.json5 192 │ └── resources 193 ├── ohosTest 194 │ ├── ets 195 │ │ ├── test 196 │ │ ├── Ability.test.ets // 自动化测试代码 197haselement/src/ 198 ├── main 199 │ ├── cpp 200 │ │ ├── types 201 │ │ │ ├── libhaselement 202 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 203 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 204 │ │ ├── CMakeLists.txt // 配置CMake打包参数 205 │ │ ├── hello.cpp // 实现Native侧的runTest接 206 │ ├── ets 207 │ │ ├── haselementability 208 │ │ ├── pages 209 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 210 │ ├── module.json5 211 │ └── resources 212 ├── ohosTest 213 │ ├── ets 214 │ │ ├── test 215 │ │ ├── Ability.test.ets // 自动化测试代码 216isarray/src/ 217 ├── main 218 │ ├── cpp 219 │ │ ├── types 220 │ │ │ ├── libisarray 221 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 222 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 223 │ │ ├── CMakeLists.txt // 配置CMake打包参数 224 │ │ ├── hello.cpp // 实现Native侧的runTest接 225 │ ├── ets 226 │ │ ├── isarrayability 227 │ │ ├── pages 228 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 229 │ ├── module.json5 230 │ └── resources 231 ├── ohosTest 232 │ ├── ets 233 │ │ ├── test 234 │ │ ├── Ability.test.ets // 自动化测试代码 235isdataview/src/ 236 ├── main 237 │ ├── cpp 238 │ │ ├── types 239 │ │ │ ├── libisdataview 240 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 241 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 242 │ │ ├── CMakeLists.txt // 配置CMake打包参数 243 │ │ ├── hello.cpp // 实现Native侧的runTest接 244 │ ├── ets 245 │ │ ├── isdataviewability 246 │ │ ├── pages 247 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 248 │ ├── module.json5 249 │ └── resources 250 ├── ohosTest 251 │ ├── ets 252 │ │ ├── test 253 │ │ ├── Ability.test.ets // 自动化测试代码 254istypedarray/src/ 255 ├── main 256 │ ├── cpp 257 │ │ ├── types 258 │ │ │ ├── libistypedarray 259 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 260 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 261 │ │ ├── CMakeLists.txt // 配置CMake打包参数 262 │ │ ├── hello.cpp // 实现Native侧的runTest接 263 │ ├── ets 264 │ │ ├── istypedarrayability 265 │ │ ├── pages 266 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 267 │ ├── module.json5 268 │ └── resources 269 ├── ohosTest 270 │ ├── ets 271 │ │ ├── test 272 │ │ ├── Ability.test.ets // 自动化测试代码 273setelement/src/ 274 ├── main 275 │ ├── cpp 276 │ │ ├── types 277 │ │ │ ├── libsetelement 278 │ │ │ │ ├── Index.d.ts // 提供JS侧的接口方法 279 │ │ │ │ ├── oh-package.json5 // 将index.d.ts与cpp文件关 280 │ │ ├── CMakeLists.txt // 配置CMake打包参数 281 │ │ ├── hello.cpp // 实现Native侧的runTest接 282 │ ├── ets 283 │ │ ├── setelementability 284 │ │ ├── pages 285 │ │ ├── Index.ets // ArkTS侧调用C/C++方法实现 286 │ ├── module.json5 287 │ └── resources 288 ├── ohosTest 289 │ ├── ets 290 │ │ ├── test 291 │ │ ├── Ability.test.ets // 自动化测试代码 292``` 293 294### 相关权限 295 296不涉及。 297 298### 依赖 299 300不涉及。 301 302### 约束与限制 303 3041.本示例仅支持标准系统上运行, 支持设备:Phone。 305 3062.本示例为Stage模型,支持API15版本SDK,版本号:5.0.3.135,镜像版本号:HarmonyOS NEXT_5.0.3.135。 307 3083.本示例需要使用DevEco Studio 5.0.3 Release (Build Version: 5.0.9.300, built on March 13, 2025)及以上版本才可编译运行。 309 310### 下载 311 312如需单独下载本工程,执行如下命令: 313 314``` 315git init 316git config core.sparsecheckout true 317echo code/DocsSample/ArkTS/JSVMAPI/JsvmUsageGuide/JsvmAboutArray > .git/info/sparse-checkout 318git remote add origin https://gitee.com/openharmony/applications_app_samples.git 319git pull origin master 320``` 321