Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript create array of objects with map

var arr = [{
  id: 1,
  name: 'bill'
}, {
  id: 2,
  name: 'ted'
}]

var result = arr.map(person => ({ value: person.id, text: person.name }));
console.log(result)
Comment

map array method create object

var arr = [{
  id: 1,
  name: 'bill'
}, {
  id: 2,
  name: 'ted'
}]

var result = arr.map(person => ({ value: person.id, text: person.name }));
console.log(result)
 Run code snippetHide results
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript websocket example code 
Javascript :: how to disable and enable a button in jquery 
Javascript :: node js check if called from command line 
Javascript :: match the pattern in the input with javascript 
Javascript :: js get json object keys 
Javascript :: string.contains javascript 
Javascript :: grepper extension firefox 
Javascript :: create select option using jquery 
Javascript :: javascript get black or white text base on color 
Javascript :: js copy paragraph onclick 
Javascript :: js unspecified parameters 
Javascript :: moment get timestamp 
Javascript :: get current html file name javascript 
Javascript :: initialize function in javascript 
Javascript :: linux cli format json 
Javascript :: Multiple children were passed to <Link with `href` of `/escritorio/opcion1` but only one child is supported 
Javascript :: read url param data in javascript 
Javascript :: jquery cget lineheight in pixels 
Javascript :: react native custom debounce input 
Javascript :: reverse method 
Javascript :: how to remove particular value in dictionary in nodehs 
Javascript :: create react expo 
Javascript :: how to get a particular line from a file in nodejs 
Javascript :: randomize an array in javascript 
Javascript :: how to get type of variable in javascript 
Javascript :: js regex for password 
Javascript :: js click change img 
Javascript :: check if a word exists in dictionary javascript 
Javascript :: on focus out javascript 
Javascript :: react native font based on viewport dimensions 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =