I have below code
const DisplayData = filteredCardMemberData.map(
(info) => (
// eslint-disable-next-line react/jsx-key -- disabling eslint rule
<div> {info.productDescription}</div>
)
);
I gives the below output
Apple
Mango
I want to convert the output as
Apple, Mango
Also, I want "Apple, Mango" to be one string, all the data should be concatenated to only string and separated by comma(,).
Can you help me.
4
Answers
For that you need to use
.join()
.Your final code look like:
You can use join method for this
If I’m correct then you are using ReactJS. Consider using React’s
useMemo
hook to memorize the result if the data is expensive to compute or frequently changes:This will only recompute the data if the dependency array (in this case,
filteredCardMemberData
) changes. Here is some other info which I think you need to read: efficient way-to-concatenate-stringsHere is Demo:- CodeSandBox