Skip to content
Advertisement

How to split a string into two and output them as two different blocks?

There is a React component –

‘function Product (props) {

JavaScript

}

export {Product}

Question: The variable prod_status: status can contain several values (for example, “new,promotion”, if so, you need to split it into two words and create a separate block for each, since now the block comes with the whole line

It is necessary like this (new, saleout, etc. in separate blocks)

enter image description here

I tried to create a function but it just outputs an array to the console

I think I’m not using the property “map” correctly

Advertisement

Answer

The problem:

The function you have created statusChecker does not return anything. Therefore when you want to print it ({statusChecker(status)}) it doesn’t do anything.

JavaScript

Solution:

return the mapped array from the function.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement