0

I have a multidimensional array, where I'd like to check if a value is in it. I've tried Array.includes("value"), but nothing came up. This is my code:

var database = [{
 "identifier": "test1",
 "extra": "information1"
},{
 "identifier": "test2",
 "extra": "information2"
},{
 "identifier": "test3",
 "extra": "information3"
}
]

How do I test if "identifier" is in my array?
Thank you!

3
  • 1
    You can use some method database.some(({identifier}) => identifier == "test1") Commented Sep 29, 2018 at 11:09
  • already answered check here stackoverflow.com/questions/5181493/… Commented Sep 29, 2018 at 11:10
  • database.length > 0 && database[0].hasOwnProperty("identifier") Commented Sep 29, 2018 at 11:36

1 Answer 1

-1

hi see below code which read each element of your database and print "identifier" value of each element.

var database = [{
 "identifier": "test1",
 "extra": "information1"
},{
 "identifier": "test2",
 "extra": "information2"
},{
 "identifier": "test3",
 "extra": "information3"
}
]

$.each(database, function(index, value) {

if(value.identifier.length>0)
  console.log(value.identifier);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

1 Comment

Question is not tagged jQuery

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.