[英]get removed and original array using splice and for loop
I'm trying to create multiple arrays from one array and then add html strings. 我正在尝试从一个数组创建多个数组,然后添加html字符串。 I use .splice()
and for
. 我使用.splice()
和for
。 My main problem is that .splice()
only shows the removed arrays and not the first. 我的主要问题是.splice()
只显示删除的数组而不是第一个。
Here's what I have so far: 这是我到目前为止所拥有的:
array = ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2" ,"c3","d1","d2","d3"]
for(var i = 0; i < array.length; i++){
array.splice(0,3);
console.log(array[0] + '<br/>' + '<a href="' + array[2] + '">' + array[1] + '</a>');
}
The only problem is that this results in: 唯一的问题是,这导致:
b1<br/><a href="b3">b2</a>
c1<br/><a href="c3">c2</a>
d1<br/><a href="d3">d2</a>
I'm missing the first array which contains the 'a' values. 我错过了第一个包含'a'值的数组。 What is the best way to output all these arrays? 输出所有这些数组的最佳方法是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.