-1

I have an array of objects(about 10 objects) with 2 properties having their respective values.

I want to check if another value of the same property exists or not.

How can i do that ?

For example

array = [{'family':'Roboto', 'type': 'Google'}, ......]

I want to search 'Roboto'. How do i do ?

EDIT:-
I am using Google Fonts API to get all the Google fonts into a single array. I have succeeded in that. Codepen. I store an array with the 'family' and 'url' of each font.

Now i want the user to search for a font. If the font is found, do something, else "Font not found"

How can i acheive this ?


Note:- A solution provided would be helpful.

2

2 Answers 2

0

If you want to find all appearance use: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

If you want to find the first appearance use: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/find

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

4 Comments

Neither of them does "check if another value of the same property exists or not"
I don't understand you? For example if he filter and his callback return an entry another value is found with this property. Or do I understand something wrong?
"check" and "or not" implies that he's looking for a boolean result value
Ok sorry, I didn't know of the existence of your function. :) I would just checking the length of the resulting array. But yours are nice to know. Thanks for that!
-1

That object is in the array, so array[0].family will return Roboto. or Just Declare the array like this: array = Object{..}. maybe I think array = array[0]; console.log(array.familly) will works too.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.