I'm doing a simple check to see if this array has an exact key value pair.
for example
testArray = [
{ "key1": "value1" },
{ "key2": "value2" },
{ "key1": "value2" )
]
How do I check to see if the array contains the exact object { "key1" : "value2" }?
Thanks for the help.
In modern browsers,
testArray.some(function(o){return o["key1"] === "value2";})
will be true
if pair is found, otherwise false
.
This assumes each object contains only one key/value pair, and that the value is never undefined
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With