To achieve what you want, you have some options. Choose which option is best for you, depending on the coding style, environment, etc. Here you are.
Option 1
You can easily replace the .toString() Array.prototype to return values separated by a vertical line ( | ) instead of a regular comma. You can do it as follows:
Array.prototype.toString = function() { return this.join("|"); };
Now you can easily do what you want:
var t = { "fields": { "a": ["99", "98"] } }; console.log("My array is: " + t.fields); // My array is: 99|98 console.log("Its first element is: " + t.fields[0]); // Its first element is: 99
By the way, changing the default methods / properties of objects is not always the best choice, because some libraries or their own methods can use them and cause errors because they have been changed.
Option 2
To achieve what you want, if you only need to make several arrays, you can change their prototype instead of the standard Array.prototype , for example:
This is the best way if you work with only a few arrays, otherwise it would be difficult to change each prototype of each array you use and it is better to do this using Array.prototype (as in my first example).
Option 3
Create your own function and use it. This is recommended because it does not modify any existing prototype method, which may lead to some errors depending on how you use your arrays.
// Create your own function function myJoin(array) { return array.join("|"); } var a = [1, 2, 3]; myJoin(a); // "1|2|3" // Or add it to the prototype Array.prototype.myJoin = function() { return this.join("|"); } var b = [11, 22, 33]; b.myJoin(); // "11|22|33"