logo CodeStepByStep logo

mergeArrayValues

Language/Type: JavaScript json objects
Author: Melissa Hovik (on 2018/10/22)

Write a function named mergeArrayValues that takes a JavaScript object with keys mapping to arrays of strings as a parameter and returns a single array containing all strings in the array values. The contents of the returned array should be in the same order as their respective array contents. For example, if the following variable were defined:

let pets = {
    "cats" : ["Miji", "Spot", "Tiger"],
    "dogs" : ["Abby", "Barney", "Clyde", "Mowgli"],
    "rocks" : ["Mr. Pebbles"]
};

the call mergeArrayValues(pets) should return the following:

["Miji", "Spot", "Tiger", "Abby", "Barney", "Clyde", "Mowgli", "Mr. Pebbles"]

You may assume the object passed is non-null.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.