CodesJava

Easy learning with example program codes

Symbol.isConcatSpreadable JavaScript

The JavaScript Symbol.isConcatSpreadable property determines if an object should be flattened to its array elements or not.

Syntax:

Array_name[symbol.isConcatSpredable] = true/false 

Returns:
Symbol corresponding to specific key.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>   
var alpha = ['X', 'Y', 'Z'];  
var beta = ['A', 'B', 'C'];  
beta[Symbol.isConcatSpreadable] = true;  
var Display = alpha.concat(beta);  
document.write(Display);   
</script>
</body>
</html>

Output:

X,Y,Z,A,B,C

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>  
const alpha = ['d', 'e'];
const numeric = [15, 52];
let alphaNumeric = alpha.concat(numeric);
 
document.write(alphaNumeric);
document.write("</br>");
 
numeric[Symbol.isConcatSpreadable] = true;
alphaNumeric = alpha.concat(numeric);
 
document.write(alphaNumeric);
 
</script>
</body>
</html>

Output:

d,e,15,52
d,e,15,52
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status