var array = [
['country', 'population'],
['someplace', 100],
['otherplace', 200]
];
var keys = array.shift();
var objects = array.map(function(values) {
return keys.reduce(function(o, k, i) {
o[k] = values[i];
return o;
}, {});
});
More Related Contents:
- Filter JSON by key value with JavaScript
- compare each 5 numbers of two array [closed]
- fetch first element of every string in array using javascript [closed]
- Convert string into several integer arrays [duplicate]
- Accesing 2d arrays from Javascript [closed]
- Determine whether an array contains a value [duplicate]
- Best way to find if an item is in a JavaScript array? [duplicate]
- Most efficient way to create a zero filled JavaScript array?
- Sort array of objects by single key with date value
- How to group by and sum an array of objects? [duplicate]
- Group objects by multiple properties in array then sum up their values
- What is “undefined x 1” in JavaScript?
- Check if an array is empty or exists
- Why Array.indexOf doesn’t find identical looking objects
- GetElementByID – Multiple IDs
- Convert object array to hash map, indexed by an attribute value of the Object
- What is the most efficient way to sort an Html Select’s Options by value, while preserving the currently selected item?
- How to convert array into string without comma and separated by space in javascript without concatenation?
- JavaScript arrays braces vs brackets
- Sort array containing objects based on another array [duplicate]
- How to find index of an object by key and value in an javascript array
- traversing through JSON string to inner levels using recursive function
- remove item from array using its name / value
- Do loops check the array.length every time when comparing i against array.length?
- Big O of JavaScript arrays
- What is the difference between “in operator” and “includes()” for JavaScript arrays
- How do I unset an element in an array in javascript?
- javascript – match string against the array of regular expressions
- How to find the coordinate that is closest to the point of origin?
- Group and count values in an array