javascript - 如何使用Javascript从数组中获取选定的字段?
问题描述
请多多包涵,我是编码新手。我正在尝试测试 Web 服务,但我遇到了一个 java 脚本数组,我需要从 10 个字段中获取 2 个字段以进行进一步测试。如果有人可以帮助我,我将不胜感激?
解决方案
尝试这个!
<script>
let colors = ["Red", "Green", "Blue"];
alert(colors[2]);
</script>
或更通用:
<script>
let colors = ["Red", "Green", "Blue"];
//Output: Blue (Note that arrays starts with 0)
PrintArrayValue(colors, 2);
function PrintArrayValue(array, index){
alert(array[index]);
}
</script>
推荐阅读
- c - 在用户输入的多个名称中查找第一个重复的名称
- line - Halcon - 获取沿线区域的最低像素
- excel - 是否有任何 Excel 公式用于比较 2 列以包含数据并计算它们的出现?
- python - 使用 Python 组合列表中的集合
- mysql - 没有重复数据的 MySQL 最近日期
- python - 通过内部文本查找 li 元素 - Selenium Python
- spring - 使用 @DeleteMapping 将导致请求方法 'POST' not supported 错误
- html - 单击时,将 div 元素设置为动画到顶部并使其具有粘性
- python - Pytorch:演变成 nan Batch loss/Log probs
- javascript - DateRangePicker 插件我怎样才能过滤当前季度/上个季度、当年/上年度中的?