Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change property name of object in array javascript

const columns = [
    { name: 'OrderNumber', title: 'Order Number' },
    { name: 'strawberry', title: 'Strawberry' },
    { name: 'vanilla', title: 'Vanilla' }
]

const options = columns.map(function(row) {

   // This function defines the "mapping behaviour". name and title 
   // data from each "row" from your columns array is mapped to a 
   // corresponding item in the new "options" array

   return { value : row.name, label : row.title }
})

/*
options will now contain this:
[
    { value: 'OrderNumber', label: 'Order Number' },
    { value: 'strawberry', label: 'Strawberry' },
    { value: 'vanilla', label: 'Vanilla' }
];
*/
Comment

change property in array of objects javascript

//change in array itself without need to another one 
arr.map(el =>{ el.bar == 1 && el.baz--} ); // don't forget {} in arrow function
Comment

change property name of object in array javascript

const columns = [
    { name: 'OrderNumber', title: 'Order Number' },
    { name: 'strawberry', title: 'Strawberry' },
    { name: 'vanilla', title: 'Vanilla' }
];

const newColumns = columns.map( item => {
  const { name: value, ...rest } = item;
  return { value, ...rest }
 }
);

console.log( newColumns );
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: js form serialize 
Javascript :: send file in patch axios react native 
Javascript :: jquery insertafter 
Javascript :: alert with sound javascript 
Javascript :: relaod the page in express 
Javascript :: get screen resolution jquery 
Javascript :: settimeout in a for loop javascript 
Javascript :: input to state 
Javascript :: new File in js 
Javascript :: javascript truncate array 
Javascript :: Vue use props in style 
Javascript :: how to sort an array of objects by a property value in javascript 
Javascript :: remove first row from table jquery 
Javascript :: count duplicate elements in array javascript 
Javascript :: svelte ondestroy 
Javascript :: javascript write text 
Javascript :: clear input field jquery 
Javascript :: how to get datetime javascript now 
Javascript :: datatable get all selected row data 
Javascript :: rename file in js 
Javascript :: javascript get random number 
Javascript :: Install react router in react app 
Javascript :: Nuxt: Nuxt auth not redirecting after logout 
Javascript :: node js send fcm 
Javascript :: divide first name and last name in javascript 
Javascript :: reload page with parameters javascript 
Javascript :: jquery selector partial class name 
Javascript :: access to model from js 
Javascript :: react history go back 
Javascript :: credit card regex 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =