js remove curly brackets from json stringify

JavaScript
[Edit]
+
0
-
0

js remove curly brackets from json stringify

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
const renderText = (object) => { const json = JSON.stringify(object); if (json[0] === '{') { return json.substring(1, json.length - 1); } return json; }; // Usage example: const user = { id: 1, name: 'Tom', age: 25 }; const text = renderText(user); console.log(text); // "id":1,"name":"Tom","age":25 // Example output: // // "id":1,"name":"Tom","age":25