I am trying to make the multiple dynamic buttons selected from the string but it is not working with the comma-separated string.
My code
{thisLabels && thisLabels.map((names, index) => (
<button type="button" className={`btn btn-outline-primary ${urltype === names ? "active" : ""}`} data-bs-toggle="button" autoComplete="off" name={names}>
{names}
</button>
))}
Works
It works for the single button if urlType is a single string (non comma-separated) for example "apple"
Doesn't work
It doesn't work if urlType has a comma-separated string for example "apple,banana,orange,etc"
Expected Result
If the urlType has the following values "apple, banana, orange" then
button-apple (active)
button-grapes (no active)
button-banana (active)
button-orange (active)
thisLabelsalways an array (never null or undefined) and removethisLabels &&. - CodeblingthisLabelsactually looks like so I can test it on my own? - PRSHLurlType. "Tokenize" is a fancy programming word which basically means split it up into an array.const types = urlType.split(/, */);then${ types.includes('apple') ? 'active' : ''}- Codebling