i have object like:
object {v: 1, b: 1, n: 1, m: 1, c: 2, d: 3}
i trying collect keys has same values , generate array (so in case [v, b, n, m]
.
so if know 1
, how can v,b,n,m
in array?
you can use object.keys()
key values of object, filter values based on condition using filter()
var obj = { v: 1, b: 1, n: 1, m: 1, c: 2, d: 3 }, val = 1; var res = object.keys(obj).filter(function(v) { return obj[v] == val; }); document.write('<pre>' + json.stringify(res, null, 4) + '</pre>');
Comments
Post a Comment