How to convert array of key–value objects to array of objects with a single property?

You can use .map var data = [ {“key”:”fruit”,”value”:”apple”}, {“key”:”color”,”value”:”red”}, {“key”:”location”,”value”:”garden”} ]; var result = data.map(function (e) { var element = {}; element[e.key] = e.value; return element; }); console.log(result); also if you use ES2015 you can do it like this var result = data.map((e) => { return {[e.key]: e.value}; }); Example

Access numeric properties of an object using dot notation

Your question seems to be about why we can’t access array and array-like elements using the dot notation like this: const v = a.0; It’s described in the ECMAScript specification: The dot notation is explained by the following syntactic conversion: MemberExpression . IdentifierName And identifiers may not start with a digit as described here: IdentifierName … Read more

Using JavaScript what’s the quickest way to recursively remove properties and values from an object?

A simple self-calling function can do it. function removeMeta(obj) { for(prop in obj) { if (prop === ‘$meta’) delete obj[prop]; else if (typeof obj[prop] === ‘object’) removeMeta(obj[prop]); } } var myObj = { “part_one”: { “name”: “My Name”, “something”: “123”, “$meta”: { “test”: “test123” } }, “part_two”: [ { “name”: “name”, “dob”: “dob”, “$meta”: { … Read more

Chrome re-ordering object keys if numerics, is that normal/expected

It’s the way v8 handles associative arrays. A known issue Issue 164 but it follows the spec so is marked ‘working as intended’. There isn’t a required order for looping through associative arrays. A simple workaround is to precede number values with letters e.g: ‘size_7’:[‘9149′,’9139’] etc. The standard will change in the next ECMAScript spec … Read more

Returning only certain properties from an array of objects in Javascript [duplicate]

This is easily done with the Array.prototype.map() function: var keyArray = objArray.map(function(item) { return item[“key”]; }); If you are going to do this often, you could write a function that abstracts away the map: function pluck(array, key) { return array.map(function(item) { return item[key]; }); } In fact, the Underscore library has a built-in function called … Read more