Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add item or nothing array js

const cond = false;
const arr = [
  ...(cond ? ['a'] : []),
  'b',
];
	// ['b']
const arr = [
  ...(cond ? [{key: 'a'}] : []),
  {key: 'b'},
];
	// [{key: 'b'}]
Comment

PREVIOUS NEXT
Code Example
Javascript :: joi custom validation read data for all fields 
Javascript :: dropdown list trigger change with value jquery 
Javascript :: upload file to s3 using pre signed url javascript 
Javascript :: javascript Program for sum of arithmetic series using loop 
Javascript :: Parsing the URL string using the WHATWG API 
Javascript :: regexp look for letter followed by 3 digits 
Javascript :: react Dark/Light mode 
Javascript :: uninstall spicetify 
Javascript :: before each function 
Javascript :: async data nuxt multiple requests 
Javascript :: verifier si chaien ade caractere apparait dans autre js 
Javascript :: django ajax json data become string 
Javascript :: loading indicator react native 
Javascript :: copy text input javascript 
Javascript :: convert .js file to ts 
Javascript :: swift urlsession remote json 
Javascript :: should i have a webpack.config.js with yarn 
Javascript :: create useTransaction 
Javascript :: Get the max value from array - divi modules 
Javascript :: Change tilte alert 
Javascript :: How to display html link inside table cell using reactjs material-table 
Javascript :: convert string to file angular 
Javascript :: jsf localdate converter 
Javascript :: angularjs GetVideos API, Cant get the key parameter inside the array 
Javascript :: angularjs How to get time difference from ZoneDateTime in javascript 
Javascript :: Why am I getting an error, "ReferenceError: categories is not defined" in AngularJS 
Javascript :: check if Popups and Redirects are allowed 
Javascript :: access language in request express 
Javascript :: Using javascript code in Jade views - if(variable) shows undefined instead of passing 
Javascript :: useEffect in React 18 in strictmode 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =