本文介绍了将字符串数组转换为整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个数组:

var endFlowArray = new Array;
for (var endIndex in flowEnd) { // <- this is just some numbers
    for (var i in dateflow) { // <- same thing
        var check = $.inArray(flowEnd[endIndex], dateflow[i]);
        if (check >= 0) {
            endFlowArray.push(i);
            flowEnd[endIndex] = null;
        }
    }
}

如何转换字符串数组:

["286", "712", "1058"]

到整数数组,如:

[286, 712, 1058]


推荐答案

控制台中的字符串是符号化的用引号括起来。通过这个事实,我们可以假设 i 是一个字符串。将它转换为整数,它将不再是一个字符串,不再有这些引号。

Strings in the console are symbolized by wrapping them in quotes. By that fact, we can assume that i is a string. Convert it to an integer and it will no longer be a string and no longer have those quotes.

endFlowArray.push(+i);

flowEnd 中的数字和 dateFlow 实际上是字符串,而不是数字。

Your "numbers" in flowEnd and dateFlow are actually strings, not numbers.

这篇关于将字符串数组转换为整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 07:45
查看更多