
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
What is the importance of Symbol.isConcatSpreadable in JavaScript?
Symbol.isConcatSpreadable
This well-known symbol is used to configure if an object should be flattened to its array elements when using the Array.prototype.concat() method. If it is false then there is no flattening of the array takes place. By default, the Symbol.IsConcatSpreadable is true. Therefore until and unless it is not declared explicitly flattening of the array can't be avoided.
Without Symbol
Example
In the following example, the symbol Symbol.IsConcatSpreadable was doesn't stated explicitly. So by default, the array was flattened as shown in the output.
<html> <body> <script> var arr1 = ['mango', 'apple', 'guava']; var arr2 = ['cashew', 'pista', 'bhadham']; var res1 = arr1.concat(arr2); console.log(res1); </script> </body> </html>
Output
["mango", "apple", "guava", "cashew", "pista", "bhadham"]
With Symbol
Example
In the following example, the symbol Symbol.IsConcatSpreadable is stated explicitly so the flattening of array didn't take place as shown ion the output.
<html> <body> <script> var arr1 = ['mango', 'apple', 'guava']; var arr2 = ['cashew', 'pista', 'bhadham']; arr2[Symbol.isConcatSpreadable] = false; var res2 = arr1.concat(arr2); console.log(res2); </script> </body> </html>
Output
["mango", "apple", "guava", Array(3)]
- Related Articles
- What is the importance of _isEqual() method in JavaScript?
- What is the importance of _without() method in JavaScript?
- What is the importance of _.initial() function in JavaScript?
- What is the importance of _.union() method in JavaScript?
- What is the importance of Navigator Object in JavaScript?
- What is the importance of str.padStart() method in JavaScript?
- What is the importance of Math.trunc() method in JavaScript?
- What is importance of startsWith() method in JavaScript?
- What is the importance of '/g' flag in JavaScript?
- What is the importance of '/i' flag in JavaScript?
- What is the symbol of mercury?
- What is the symbol of battery?
- What is the symbol of alcohol?
- What is the importance of ES6's template strings in JavaScript?
- What is the importance of '+' operator in type conversion in JavaScript?

Advertisements