
- 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
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 Articles
- Convert JSON array into normal json in JavaScript
- Transform data from a nested array to an object in JavaScript
- How to transform a JavaScript iterator into an array?
- 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
- Group objects inside the nested array JavaScript
- Accessing and returning nested array value - JavaScript?
- Convert array into array of subarrays - JavaScript
- Finding the maximum in a nested array - JavaScript
- JavaScript - summing numbers from strings nested in array

Advertisements