Hello.
My question is very basic but I can not find/understand the answer anywhere.
How check if the name-value "name": value in an object.
I know that with Object.keys() method we can checking the names of the properties.
I know too that with Object.name or Object["name"] we can see the value of the "named-name" property.
But if I have a singleton {"name": value} and want to check many large object for it, is it a direct method?
For example object 1 is {'a': 'lphabet', 'b': "cycle'} and I search 'a': 'bsurd'.
Tthank you in advance
kouty
0
Junior Poster in Training
Recommended Answers
Jump to PostYou cannot, in any fast way, compare objects directly in JS.
The only way to check values is to iterate through the object and compare values directly for what you are looking for (or, as you pointed out, simply check the value directly). Since all an object really is on …
Jump to PostFrom your
myFriend
variable data structure, you don't need to iterate it that way. It is already an associated array (as Object). You simply call for the value usinglastName
key.for (var friend in myFriends) { if (friend["lastName"]=="Michel") { myFamilyMembers.push(friend); } }
Jump to PostIn your example, myFriends is an array of objects. (Ln. 1)
Your iteration is for object notation on Ln. 8. the for ... in construct only works on "objects" that have properties. Now, since everything in javascript is an extension of a root "Object" (other than primitives) your code does …
All 10 Replies
ryantroop
177
Practically a Master Poster
kouty
0
Junior Poster in Training
Taywin
312
Posting Virtuoso
kouty
0
Junior Poster in Training
ryantroop
177
Practically a Master Poster
actorY
0
Newbie Poster
kouty
0
Junior Poster in Training
ryantroop
177
Practically a Master Poster
kouty
0
Junior Poster in Training
kouty
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.