I have a quick question about returning the values from an object using JavaScript.
More specifically I want to write a function that takes an object as a parameter and then returns the values in an array.
I know that its easy to do this with the object keys as one can just use object.keys(), but I was wondering if there was a good way to do this for values?
Sorry if this is a basic question, I've done some searching around and can't seem to find anything that helps.
Keenan Lidral-Porter :
You can iterate through the object, push the values to an array, and then return that:\n\nvar grabValues = function(obj){\n var results = [];\n\n for(var key in obj){\n results.push(obj[key]);\n }\n\n return results;\n};\n",
2014-12-28T02:09:09
Born2Code :
There are a lot of javascript resources that can help with this, but here is an example function.\n\n\r\n\r\nfunction obj2array(o) {\r\n var arr=[];\r\n for(var x in o) {\r\n arr.push(o[x]); \r\n }\r\n return arr;\r\n}",
2014-12-28T02:09:50