Baba
Baba

Reputation: 2229

concatenating fields in react.js method

I have the method below in my react.js application. I will like to concatenate this line {dt.productCode} {dt.sizeCode} {dt.itemWearerName} such that asterisk will be between them.

        1234*xl*tester

How can I achieve that?

         renderInvoicesProducts(){
                return this.state.invoicesProducts.map((dt, i) => {
                    return (
                        <MenuItem key={i} value={dt.customerInvoiceProductId}>
                            {dt.productCode} {dt.sizeCode} {dt.itemWearerName}
                        </MenuItem>
                    );
                });
            }

Upvotes: 0

Views: 39

Answers (3)

Colin Ricardo
Colin Ricardo

Reputation: 17259

If you have some number of things and you want to add something between them, then .join() can be a good approach.

const things = ['one', 'two', 'three'];
const s = things.join('*')
console.log(s) // one*two*three

You can read more about .join here.

Upvotes: 0

L Dorado
L Dorado

Reputation: 51

When I want space between values like that, I use {' '}. [Note the spacing given in between the quotes] Try to add asterisk in similar way and check.

Upvotes: 0

sjdm
sjdm

Reputation: 589

You cant just put an asterisk between them as such?

     renderInvoicesProducts(){
            return this.state.invoicesProducts.map((dt, i) => {
                return (
                    <MenuItem key={i} value={dt.customerInvoiceProductId}>
                        {dt.productCode}*{dt.sizeCode}*{dt.itemWearerName}
                    </MenuItem>
                );
            });
        }

Upvotes: 1

Related Questions