在javascript中迭代整数,其中每个值等于一个位数

在javascript中迭代整数,其中每个值等于一个位数,javascript,arrays,loops,integer,iteration,Javascript,Arrays,Loops,Integer,Iteration,我想使用$.each()循环迭代整数中的数字。 整数是作为另一个数组的索引生成的,尽管我不确定这是否有区别 Javascript var words = [ "This", "is", "an", "array", "of", "words","with", "a", "length", "greater", "than", "ten." ]; var numbers = []; $.each(words, function(i,word) { $.each(i, function(in

我想使用
$.each()
循环迭代整数中的数字。 整数是作为另一个数组的索引生成的,尽管我不确定这是否有区别

Javascript

var words = [ "This", "is", "an", "array", "of", "words","with", "a", "length", "greater", "than", "ten." ];
var numbers = [];
$.each(words, function(i,word) {
    $.each(i, function(index,value) {
        $(numbers).append(value);
    });
});
我希望数组
数字
等于以下数组:

[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0, 1, 1 ]
其中最后四个条目,
[…1,0,1,1]
是通过迭代
[…“than”,“ten.”]
数组中条目的索引生成的。

让words=[“This”,“is”,“an”,“array”,“of”,“words”,“with”,“a”,“length”,“better”,“than”,“ten.”;
让numbers=words.map((w,i)=>i.toString().split(“”).map(Number))//映射到数字数组中
numbers=Array.prototype.concat.call(…numbers)//把他们都干掉
控制台日志(编号)
让words=[“This”,“is”,“an”,“array”,“of”,“words”,“with”,“a”,“length”,“better”,“than”,“ten.”;
让numbers=words.map((w,i)=>i.toString().split(“”).map(Number))//映射到数字数组中
numbers=Array.prototype.concat.call(…numbers)//把他们都干掉

控制台日志(编号)than
是10,你从10=1,0和11=1,1中得到1,0?您正在将索引更改为字符串并对其进行迭代?为什么?基本上是的。我想把整数转换成字符串值,所以1变成了“一”,但是,我想用它来做的是,插件太过分了。。。所以我只想知道将整数作为单个数字读取的最有效方法,而这似乎是解释我期望结果的最合乎逻辑的线性方法。。。。或者我今天只是盯着代码看了太久,需要休息一下……我不理解你的问题。你想计算一个整数的汇率吗?这怎么可能?嗯?你怎么得到1,0,1,1?你是说
than
是10,你从10=1,0和11=1,1中得到1,0?您正在将索引更改为字符串并对其进行迭代?为什么?基本上是的。我想把整数转换成字符串值,所以1变成了“一”,但是,我想用它来做的是,插件太过分了。。。所以我只想知道将整数作为单个数字读取的最有效方法,而这似乎是解释我期望结果的最合乎逻辑的线性方法。。。。或者我今天只是盯着代码看了太久,需要休息一下。。。