0

I'd like to extend each object in the array of objects below with an array of value* as seen below:

array = [object, object, object]

object = {key: array2, key2: value, key3: value}

array2 = [object2, object2]

object2 = {key: object3, key2: child, key3: object4}

object4 = {key: value, key2: value, key3: value*} 

How do I write an underscore operation to extend the objects in the original array to include an array of value* as illustrated above?

1 Answer 1

1

It is possible using double _.each as a wrapper

_.each( array, function( item /* object */ )
{
    _.each( item.key /* array2 */, function( item /* object2 */ )
    {
        _.extend( item.key3 /* object4 */, {key3:5} )
    })
});
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that but it did not bring the last key value pair to the front like I hoped. I've almost found it now and will publish my answer soon.
Actually I can't publish it because I changed my data structures so much to accomodate the change I was looking for that it no longer relates to the question . . .
Thanks for following up!

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.