Use Array#map
to convert each value into a different value:
var newArr = arr.map(function(value) {
return {name: value};
});
Array#map
applies the callback to each element in the array and returns a new array containing the return values of the callback.
More Related Contents:
- Most efficient method to groupby on an array of objects
- JavaScript merging objects by id
- Add property to an array of objects
- Comparing two arrays of objects, and exclude the elements who match values into new array in JS
- Javascript group objects by property [closed]
- break array of objects into separate arrays based on a property
- Sorting an Array of JavaScript Objects a Specific Order (using existing function)
- Remove duplicates in an object array Javascript
- How to merge two arrays in JavaScript and de-duplicate items
- How to add same elements to javascript array n times
- How to filter an array from all elements of another array
- Get the closest number out of an array
- forEach on querySelectorAll not working in recent Microsoft browsers
- How can I convert the “arguments” object to an array in JavaScript?
- How to convert an array of objects to object with key value pairs
- forEach on array of undefined created by Array constructor
- using underscore’s “difference” method on arrays of objects
- Alternative or polyfill for Array.from on the Internet Explorer
- How to Compare two Arrays are Equal using Javascript? [duplicate]
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Delete duplicate elements from an array [duplicate]
- Why Array.forEach is slower than for() loop in Javascript? [duplicate]
- Array destructuring in JavaScript
- Array.includes() to find object in array
- String split returns an array with more elements than expected (empty elements)
- How to use Array.prototype.filter with async?
- Creating an array consisting of the largest values of each sub-array does not work as expected
- Array.of vs “[ ]”. When to use Array.of over “[ ]”?
- Array.push return pushed value?
- Array of object deep comparison with lodash