是否可以在jquery中使用整数数组

时间:2013-08-28 09:41:00

标签: javascript jquery

我有ToothSequence数组,其中包含所有整数类型值

每当我想要比较元素或添加整数时我必须parseInt如图所示parseInt(ToothSequence[i]) + 1

 var ToothSequence = $("#hndBridge").val().split("|");
for (i = 1; i <= ToothSequence.length; i++) {
  if (parseInt(ToothSequence[i]) + 1 == parseInt(ToothSequence[i + 1]))
  {

是否可以在jquery中生成整数数组?如果没有请建议我

1 个答案:

答案 0 :(得分:6)

你可以这样做:

var ToothSequence = $("#hndBridge").val().split("|").map(function(e) { return +e; });

+e会将e转换为数字。

- 对于Array没有map方法的旧浏览器,请改用$.map -

var ToothSequence = $.map($("#hndBridge").val().split("|"), function(e) { return +e; });
相关问题