0

How do I check if a JSON object have key are duplicate, just get distint the key and not use foreach function? Such as:

var objectData = {[value1: abc], [value1: abc], [value2: bcd]}

If a key doesn't exist, and I try to access it, will it return undefined? Or get the error?

Binh LE
  • 387
  • 5
  • 17
  • 3
    your object is an array and your arrays are objects. => `[{value1: abc}, {value1: abc}, {value2: bcd}]` – Nina Scholz Feb 10 '16 at 18:59
  • Think how can I check the key in an object if it has duplicate not using "for" or "for each"? – Binh LE Feb 10 '16 at 19:02
  • the key duplicate or the value of a object's key is duplicate? – rck6982 Feb 10 '16 at 19:07
  • Right now, objectData is an object that is full of arrays. Is that intended? Or is objectData supposed to be an array of objects? Or is objectData supposed by an object, with multiple objects as its properties? – trenthaynes Feb 10 '16 at 19:12
  • Yes, above just a sample. I just want to check key is duplicate in an object not use "for" function, that it. – Binh LE Feb 10 '16 at 19:15
  • Possible duplicate of [Remove duplicate objects from an array using javascript](http://stackoverflow.com/questions/19501441/remove-duplicate-objects-from-an-array-using-javascript) – CSS Feb 10 '16 at 19:38

1 Answers1

0

If this is meant to be an array of JSON objects:

var objectData = [ {"value1": "abc"}, {"value1": "abc"}, {"value2": "bcd"} ];

Then your answer lies within the responses to this question: Remove duplicates from an array of objects in javascript or this one Remove duplicate objects from an array using javascript.

If your notation accurately reflects what is produced by your system (or your own coding), you may want to rework it a bit so it makes sense.

Hope that helps.

Community
  • 1
  • 1
CSS
  • 412
  • 5
  • 17