Published
Edited
Aug 9, 2019
Insert cell
md`# Conditionally adding keys to JavaScript objects using spread operators and short-circuit evaluation`
Insert cell
// See https://medium.com/@mikeh91/conditionally-adding-keys-to-javascript-objects-using-spread-operators-and-short-circuit-evaluation-acf157488ede for more details
Insert cell
amplitude = 26
Insert cell
freq = "WEEKLY"
Insert cell
interval = 23
Insert cell
a =
({
...(amplitude && true) && { amplitude: amplitude }, //YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY
...interval && { interval: interval }, //The interval between each freq iteration.
dfd: 3
})
Insert cell
b =
({
...(amplitude && true) && { amplitude: amplitude }, //YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY
...interval && { interval: interval }, //The interval between each freq iteration.
dfd: 3,
...[0] && { name: [0] }, //The interval between each freq iteration.

})
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more