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 :: how to check if connected to internet js 
Javascript :: random array javascript 
Javascript :: javascript combine array of arrays 
Javascript :: relative width and height image react native 
Javascript :: nodejs readdir 
Javascript :: getelementbyxpath 
Javascript :: regex match entire words only js 
Javascript :: validatorjs get all errors 
Javascript :: uppercase first letter of each word javascript 
Javascript :: jquery scroll to div with offset 
Javascript :: check if variable is undefined or null jquery 
Javascript :: how to print the value of variable in javascript in html 
Javascript :: javascript object first key 
Javascript :: run react app in react 18 
Javascript :: p5.js add class to button 
Javascript :: run a loop inside a console.log no blank line 
Javascript :: modify margin top javascript 
Javascript :: javascript fill array with range 
Javascript :: javascript object dont sort 
Javascript :: how to add parameters to url javascript 
Javascript :: vue get props into data 
Javascript :: javascript order array by date 
Javascript :: inarray javascript 
Javascript :: style before javascript 
Javascript :: add css in javascript 
Javascript :: hide label chratjs 
Javascript :: for each js 
Javascript :: apa itu this pada javascript 
Javascript :: chartjs how to disable hover lable 
Javascript :: js keydown only once 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =