Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array of objects to array

const kvArray = [{ key: 1, value: 10 },
                 { key: 2, value: 20 },
                 { key: 3, value: 30 }];

const reformattedArray = kvArray.map(({ key, value}) => ({ [key]: value }));

// reformattedArray is now [{1: 10}, {2: 20}, {3: 30}],

// kvArray is still:
// [{key: 1, value: 10},
//  {key: 2, value: 20},
//  {key: 3, value: 30}]
Comment

PREVIOUS NEXT
Code Example
Javascript :: npm auth0-react 
Javascript :: express-ejs-layouts install 
Javascript :: get element class javascript 
Javascript :: wordpress ajax file upload 
Javascript :: how to send a message discord.js 
Javascript :: datatables get all rows 
Javascript :: create array with number js 
Javascript :: js get last element of an array 
Javascript :: remove a user from a reaction discord.js 
Javascript :: jquery input only integers 
Javascript :: keyboard event js 
Javascript :: use js to save data in laravel using route 
Javascript :: chart.js chart is not defined 
Javascript :: react use same useState for multiple inputs 
Javascript :: props vue 3 
Javascript :: python range in javascript 
Javascript :: javascript click coordinates on page 
Javascript :: convert json string into json object 
Javascript :: custom event handler javascript 
Javascript :: link on click jquery 
Javascript :: text inside an image component react native 
Javascript :: how to remove middle characters in string javascript 
Javascript :: ajax form picture upload 
Javascript :: next js material ui typescript 
Javascript :: jquery target partial id 
Javascript :: javascript clear radio button 
Javascript :: javascript get all child elements 
Javascript :: sequelize update column type 
Javascript :: javascript vue.js right click 
Javascript :: js object get type 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =