如何使用Javascript从数组中获取选定字段?

时间:2018-09-25 21:10:08

标签: javascript arrays testcomplete

请多多包涵,我是编码的新手。我正在尝试测试Web服务,并且遇到了Java脚本数组,我需要从10个字段中获取2个字段以进行进一步测试。如果有人可以帮助我,我将不胜感激?

1 个答案:

答案 0 :(得分:0)

试试看!

<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>