
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Transform nested array into normal array with JavaScript?
Let’s say the following is our nested array −
const arrayObject = [ [ { Name: "John" }, { countryName: "US" } ], [ { subjectName: "JavaScript" }, { teacherName: "Mike" } ] ];
To transform nested array into normal array, use the concept of flat() as in the below code −
Example
const arrayObject = [ [ { Name: "John" }, { countryName: "US" } ], [ { subjectName: "JavaScript" }, { teacherName: "Mike" } ] ]; const output = arrayObject.flat(); console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo50.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo50.js [ { Name: 'John' }, { countryName: 'US' }, { subjectName: 'JavaScript' }, { teacherName: 'Mike' } ]
- Related Questions & Answers
- Convert JSON array into normal json in JavaScript
- Transform data from a nested array to an object in JavaScript
- Transform a masked array into a flexibletype array with torecords() in Numpy
- Simplifying nested array JavaScript
- Transform a masked array into a flexibletype array in Numpy
- Grouping nested array in JavaScript
- Convert nested array to string - JavaScript
- Recursion - Sum Nested Array in JavaScript
- Join in nested array in JavaScript
- Convert array into array of subarrays - JavaScript
- Group objects inside the nested array JavaScript
- Accessing and returning nested array value - JavaScript?
- How to convert JSON Array to normal Java Array?
- Query array of nested string with MongoDB?
- Best way to flatten an object with array properties into one array JavaScript
Advertisements