179
rated 0 times
[
183]
[
4]
/ answers: 1 / hits: 5623
/ 10 Years ago, thu, may 8, 2014, 12:00:00
So if I had:
A=['a','b','c'];
B=[];
for (var i = 0;i<7;i++){
B.push(A[i])
}
I would get
B=[a, b, c, undefined, undefined, undefined, undefined]
Instead I want
B= [a,b,c]
So I guess I would need something like
for (var i = 0;i<7;i++){
B.push(A[i] unless A[i] is undefined. Then don't push anything)
}
How would I do this in Javascript?
More From » arrays