I have following array like below
[1,null,null,2]
I want to implode make it as string like below
1,null,null,2
I tried
temparr.join(',')
But I am getting
1,,,2
How do i preserve the keyword null.
You could convert the values to string in advance, because undefined or null values are empty string by converting with join.
If an element is
undefined,nullor an empty array[], it is converted to an empty string.
const array = [1, null, null, 2];
console.log(array.map(String).join(','));
nullfirst? Or by writing your own join function, that takes your special requirement into account.