const arrays = [["$6"],["$12"],["$25"],["$25"],["$18"],["$22"],["$10"]];const merge3 = arrays.flat(1); //The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.console.log(merge3);
function flatten(arr) {
var temp = [];
function recursiveFlatten(arr) {for(var i = 0; i < arr.length; i++) {if(Array.isArray(arr[i])) {recursiveFlatten(arr[i]);} else {temp.push(arr[i]);}}}recursiveFlatten(arr);return temp;}
function flattenArray(a){
var aFinal = [];
(function recursiveArray(a){
var i,iCount = a.length;
if (Object.prototype.toString.call(a) === '[object Array]') {for (i = 0; i < iCount; i += 1){recursiveArray(a[i]);}} else {aFinal.push(a);}
})(a);
return aFinal;
}
var aMyArray = [6,3,4,[12,14,15,[23,24,25,[34,35],27,28],56],3,4];
var result = flattenArray(aMyArray);
console.log(result);
function deepFlatten(arr) {return flatten( // return shalowly flattened arrayarr.map(x=> // with each x in arrayArray.isArray(x) // is x an array?? deepFlatten(x) // if yes, return deeply flattened x: x // if no, return just x))}
var arr = ["abc",[[[6]]],["3,4"],"2"];
var s = "[" + JSON.stringify(arr).replace(/\[|]/g,'') +"]";var flattened = JSON.parse(s);
console.log(flattened)
/*jshint esversion: 6 */
// nested array for testinglet nestedArray = ["firstlevel", 32, "alsofirst", ["secondlevel", 456,"thirdlevel", ["theinnerinner", 345, {firstName: "Donald", lastName: "Duck"}, "lastinner"]]];
// wrapper function to protect inner variable tempArray from global scope;function flattenArray(arr) {
let tempArray = [];
function flatten(arr) {arr.forEach(function(element) {Array.isArray(element) ? flatten(element) : tempArray.push(element); // ternary check that calls flatten() again if element is an array, hereby making flatten() recursive.});}
// calling the inner flatten function, and then returning the temporary arrayflatten(arr);return tempArray;}
// example usage:let flatArray = flattenArray(nestedArray);
function flatten(array) {// reduce traverses the array and we return the resultreturn array.reduce(function(acc, b) {// if is an array we use recursion to perform the same operations over the array we found// else we just concat the element to the accumulatorreturn acc.concat( Array.isArray(b) ? flatten(b) : b);}, []); // we initialize the accumulator on an empty array to collect all the elements}
function flatArray([x,...xs]){return x ? [...Array.isArray(x) ? flatArray(x) : [x], ...flatArray(xs)] : [];}
var na = [[1,2],[3,[4,5]],[6,7,[[[8],9]]],10];fa = flatArray(na);console.log(fa);
function flatten(obj) {var out = [];function cleanElements(input) {for (var i in input){if (input[i]instanceof Array){cleanElements(input[i]);}else {out.push(input[i]);}}}cleanElements(obj);return (out);}
function flatten(input) {let result = [];
function extractArrayElements(input) {for(let i = 0; i < input.length; i++){if(Array.isArray(input[i])){extractArrayElements(input[i]);}else{result.push(input[i]);}}}
extractArrayElements(input);
return result;}
// let input = [1,2,3,[4,5,[44,7,8,9]]];// console.log(flatten(input));
// output [1,2,3,4,5,6,7,8,9]
function flattenArray(deepArray) {// check if Arrayif(!Array.isArray(deepArray)) throw new Error('Given data is not an Array')
const flatArray = deepArray.flat() // flatten arrayconst filteredArray = flatArray.filter(item => !!item) // filter by Booleanconst uniqueArray = new Set(filteredArray) // filter by unique values
return [...uniqueArray] // convert Set into Array}