Foreach inside array.map()
<p>I'm trying to map values to a new array. The problem is that the property that I'm mapping can either be a number or an array.</p>

<p>I have a problem when it comes to arrays, because my result is an associative array. My goal is to turn <code>[[1,2,3], [1,2,3]]</code> (see below) in to <code>[1,2,3,1,2,3]</code>. In other words; just make it a one dimensional array.</p>

<p>I've tried with a foreach loop inside the map(), without success. Any ideas?</p>

<pre><code>var list = [{ foo: 1, bar: [1,2,3] }, { foo: 2, bar: [1,2,3] }];

var retArr = list.map(function (v) {

    return v.bar;

});

console.log(retArr); // [[1,2,3], [1,2,3]]
</code></pre>

<hr>

<pre><code>var list = [{ foo: 1, bar: [1,2,3] }, { foo: 2, bar: [1,2,3] }];

var retArr = list.map(function (v) {

    if($.isArray(v.bar)){

        $.each(v.bar, function(i, v){

            return v;
        });

    } else {

        return v.bar;
    }
});

console.log(retArr); // [undefined, undefined] 
</code></pre>

<p><a href="http://jsfiddle.net/Mck7N/" rel="nofollow">http://jsfiddle.net/Mck7N/</a></p>
