“aplatir JS” Réponses codées

Javascript aplati un tableau

let arr = [
    [1, 2],
    [3, 4],
    [5, 6][7, 8, 9],
    [10, 11, 12, 13, 14, 15]
];
let flatArray = arr.reduce((acc, curVal) => {
    return acc.concat(curVal)
}, []);

//Output:  [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ]
Elated Earthworm

aplatir un tableau javascript

var arrays = [
  ["$6"],
  ["$12"],
  ["$25"],
  ["$25"],
  ["$18"],
  ["$22"],
  ["$10"]
];
var merged = [].concat.apply([], arrays);

console.log(merged);
Bad Bison

aplatir

const arr = [1, 2, [3, 4]];

// To flat single level array
arr.flat();
// is equivalent to
arr.reduce((acc, val) => acc.concat(val), []);
// [1, 2, 3, 4]

// or with decomposition syntax
const flattened = arr => [].concat(...arr);
Poised Puffin

aplatir JS

import { flatten } from "ramda";

const flattenArray = flatten([1, [2, 3]])
Lucas Charvolin

Réponses similaires à “aplatir JS”

Questions similaires à “aplatir JS”

Plus de réponses similaires à “aplatir JS” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code