0

I have

array.length=3
array2=['[A]','[B]','[C]','[D]'];

based on array.length, i want to create set of string
example, if lenght=3
output= [A][B][C]

example, if lenght=2
output= [A][B]

i tried using for loop but it prints vertically and could not store and append ,I have no idea how to print horizontally,any ideas or help would be really appreciated
my output is

[A]
[B]
[C]
AND Then i store it in variable and tried appending them. I know this is not the best idea

2
  • "i tried using for loop but it prints vertically and could not store and append" - this doesn't make a lot of sense. Commented Dec 8, 2014 at 11:35
  • @andy I updated the question. I hope you understand now :) Commented Dec 8, 2014 at 11:37

1 Answer 1

1

Try

console.log(array2.slice(0, array.length).join(''));

Though I don't see any point in having the first array. You could use just var len = 3;.

Sign up to request clarification or add additional context in comments.

1 Comment

awesome. That worked bro. I will learn more about slice and join. Thanks alot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.