Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript optional add object key

const gender = 'male'
const data = {
  first_name: 'Joe',
  last_name: 'Doe',
  ...(gender && {gender})
}
console.log(data)
// {
//   first_name: 'Joe',
//   last_name: 'Doe'
//   gender: 'male'
// }
Comment

PREVIOUS NEXT
Code Example
Javascript :: functional component state management 
Javascript :: javaScript Math.log2() Method 
Javascript :: p5js left mouse click 
Javascript :: how to create react app 
Javascript :: multiple export in react 
Javascript :: constructor function 
Javascript :: import in react js 
Javascript :: datatable table header not responsive 
Javascript :: Angular empty object 
Javascript :: find class 
Javascript :: how to make alert in javascript 
Javascript :: javascript program to find leap years between two years 
Javascript :: react-floating-whatsapp 
Javascript :: updatable time js 
Javascript :: javascript things to remember 
Javascript :: change react native app name 
Javascript :: Stop setInterval call in JavaScript 
Javascript :: how to convert a string to a mathematical expression programmatically javascript 
Javascript :: jquery var_dump array 
Javascript :: how to get data form 
Javascript :: prevent click other tab bootstrap tabs 
Javascript :: nestjs 
Javascript :: returned value by findOneAndUpdate 
Javascript :: what is undefined 
Javascript :: How to pass variables from js to html node 
Javascript :: javascript array push 
Javascript :: js object sort 
Javascript :: javascript simple hash 
Javascript :: glide.js autoplay 
Javascript :: canvas drawimage resize quality 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =