0

I have following object

object = {
  "key1": "value1",
  "key2": "value2",
  "key3": [
     "arrayKey1": "arrayValue1",
     "arrayKey2": "arrayValue2",
     "arrayKey3": "arrayValue3"
   ]
};

When i am using _.omit(object, key3) is working fine. As it is removing the 'key3' correctly. but what if i want to remove the arrayKey2 only and not the whole key3 ?

1
  • 2
    Your syntax is invalid. Is that an array or an object now? Commented Oct 14, 2013 at 13:57

1 Answer 1

1

If object.key3 is actually an array:

object.key3 = _.reject(object.key3, function(val, idx){ return idx == 1 })
// Or using the new ES6 syntax:
object.key3 = _.reject(object.key3, (val, idx) => idx == 1)

If object.key3 is an object:

object.key3 = _.omit(object.key3, 'arrayKey2')
Sign up to request clarification or add additional context in comments.

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.