// join an array together into a string// array for the .join() methodlet numbers =[3,1,6]let string = numbers.join(', ')// returns '3, 1, 6'// Also works the same just for an array of STRINGS
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 stringprint_r(json_decode($str_json));//printing array after convert json string to array
exit;// exiting further execution to check resutls
// 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
const array =[0,1,2,3,4,5];/*
Array.prototype.join(separator);
Converts each element of the array into a string
and joins each element into one long string with
each element separated by the separator.
*/const string1 = array.join("");console.log(string1);// -> 012345const string2 = array.join(",");console.log(string2);// -> 0,1,2,3,4,5const string3 = array.join(", ");console.log(string3);// -> 0, 1, 2, 3, 4, 5
// If you want to split on a specific character in a string:const stringToSplit ='01-02-2020';console.log(stringToSplit.split('-'));// ["01", "02", "2020"]// If you want to split every character:const stringToSplit ='01-02-2020';console.log(Array.from(stringToSplit));// ["0", "1", "-", "0", "2", "-", "2", "0", "2", "0"]
/* 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']