Languages
[Edit]
EN

JavaScript - combine names (e.g. CSS class names)

10 points
Created by:
Ela-Davey
663

In this short article, we would like to show how using JavaScript, create simple function that combines names omitting empty or falsy values.

Quick solution: 

 

Motivation

Edit

Imagine you want to assign multiple class names to className property omitting undefined one in React application, e.g.

Let's suppose dark mode style is undefined, so we expect to get finally:

 

Alternative titles

  1. JavaScript - combine names (e.g. style class names)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join