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

update property in object in array javascript

var result = foo.map(el => el.bar == 1 ? {...el, baz: [11,22,33]} : el);
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

update property of object in array javascript

foo.forEach(function(obj) {
    if (obj.bar === 1) {
        obj.baz[0] = 11;
        obj.baz[1] = 22;
        obj.baz[2] = 33;
        // Or: `obj.baz = [11, 22, 33];`
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to iterate array in javascript 
Javascript :: string number to array 
Javascript :: node -r dotenv/config 
Javascript :: discord.js setactivity 
Javascript :: find my url in nodejs 
Javascript :: js if string not empty 
Javascript :: how to set visibility in javascript of html title 
Javascript :: merge sort javascript 
Javascript :: binary tree implementation javascript 
Javascript :: custom timestamp name mongoose 
Javascript :: javascript split string by multiple characters 
Javascript :: remove table line button html using javascript 
Javascript :: get url parameters javascript 
Javascript :: how to convert string to camel case in javascript 
Javascript :: ReactDOMServer import 
Javascript :: get localstorage value 
Javascript :: react-stripe-checkout 
Javascript :: val jquery 
Javascript :: vue js routue push 
Javascript :: innertext 
Javascript :: siwtch case javascript 
Javascript :: javascript get query params from url 
Javascript :: angular rellax 
Javascript :: how to counts date from moment js 
Javascript :: github pages react route 
Javascript :: eslint disable tag 
Javascript :: js wait for element to load 
Javascript :: change text in javascript 
Javascript :: vercel rewrites 
Javascript :: Capitalize first letter of string on json sending 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =