1

let's say that we have two arrays:

var a = ['Tomo', 'Joseph','Alan'];
var b = ['Brzica', 'Smith', 'Adams'];

How to merge these arrays using undersoreJS (or plain javascript if underscore is not the way to do it) to get:

c=['Tomo Brzica','Joseph Smith', 'Alan Adams']

Thanks in advance!

2 Answers 2

4

You can try this

c = _.map(_.zip(a, b), function (elem) {
    return elem.join(" ");
});
Sign up to request clarification or add additional context in comments.

Comments

3

try this:

c = _.map(a, function (item, index) {
   return item + " " + b[index];
})

Comments

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.