How would I get this array to be passed in as a set of strings to the function? This code doesn't work, but I think it illustrates what I'm trying to do.
var strings = ['one','two','three']; someFunction(strings.join("','")); // someFunction('one','two','three');
Thanks!
So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.
Splitting the Array Into Even Chunks Using slice() Method The easiest way to extract a chunk of an array, or rather, to slice it up, is the slice() method: slice(start, end) - Returns a part of the invoked array, between the start and end indices.
For ES6 JavaScript you can use the special destructuring operator :
var strings = ['one', 'two', 'three']; someFunction(...strings);
Use apply().
var strings = ['one','two','three']; someFunction.apply(null, strings); // someFunction('one','two','three');
If your function cares about object scope, pass what you'd want this
to be set to as the first argument instead of null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With