xxxxxxxxxx
// convert an array to string javascript
// using reduce()
let array = ['A', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'];
let output = array.reduce((a, b) => a + ' ' + b);
console.log(output); //A quick brown fox jumps over the lazy dog
// using join()
let output1 = array.join(" ");
console.log(output1); //A quick brown fox jumps over the lazy dog
xxxxxxxxxx
var cars = ["Volvo", "BMW", "Audi", "Chevrolet"];
console.log(cars.toString());
//Output: Volvo,BMW,Audi,Chevrolet
xxxxxxxxxx
const cities = ['London', 'Paris', 'Tokyo'];
const joinedCities = cities.join();
console.log(joinedCities); // London,Paris,Tokyo
xxxxxxxxxx
print_r($request->education); //It is an array print
$str_json = json_encode($request->education); //array to json string conversion
echo $str_json; // printing json string
print_r(json_decode($str_json)); //printing array after convert json string to array
exit; // exiting further execution to check resutls
xxxxxxxxxx
const classNames = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
function getClassName() {
return classNames.join(" ").toString()
}
console.log(getClassName()) // a b c d e f g h i j
xxxxxxxxxx
/* You can use map and pass the String constructor as a function,
which will turn each number into a string: */
sphValues.map(String) //=> ['1','2','3','4','5']