Is there a way to get an object property from the value of another object
For example ( Get the object in id where object.name = "somename"? I need an ID that is the object, but I only know the name. I think you're trying to do this because the array of objects, because it means otherwise is not. Based on your desired browser support, The code looks something like this: Here is a jsfiddle link:
filter on
Array.prototype . If necessary, you can also shimla it.
var list = รข ???? [{Id: 1, name: 'Bob'}, {id: 2, name: 'gym'}, {id: 3, name: 'sam'}, {id: 4, name: 'tim'}]; Var sams = list.filter (function (obj) {return obj.name == 'sam';}); Console.log (sams [0] .id);
Comments
Post a Comment