gpt4 book ai didi

javascript - 如何在javascript中声明特定类型的数组

转载 作者:搜寻专家 更新时间:2023-11-01 05:23:12 25 4
gpt4 key购买 nike

是否可以在 java 脚本中将数组显式声明为 int 数组(或任何其他类型)?

var arr: Array(int) 这样的东西会很好......

最佳答案

var StronglyTypedArray=function(){
this.values=[];
this.push=function(value){
if(value===0||parseInt(value)>0) this.values.push(value);
else return;//throw exception
};
this.get=function(index){
return this.values[index]
}
}

EDITS:按如下方式使用

var numbers=new StronglyTypedArray();
numbers.push(0);
numbers.push(2);
numbers.push(4);
numbers.push(6);
numbers.push(8);
alert(numbers.get(3)); //alerts 6

关于javascript - 如何在javascript中声明特定类型的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23061379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com