Ich versuche, den Wert des ersten Schlüssel: Wert-Paar auf jeden Wert im Array des zweiten Schlüssel: Wert-Paar beim Entfernen der Schlüssel aus dem Buch-Array, was zu einer Liste, die dauert dieser Eingang:flattern Objekt innerhalb Array
var fictionCatalog = [
{
author: 'Michael Crichton',// push into each book
books: [
{name: 'Sphere', price: 10.99},
{name: 'Jurassic Park', price: 5.99},
{name: 'The Andromeda Strain', price: 9.99},
{name: 'Prey', price: 5.99}
]
}
]
und diesen Ausgang log:
[
[ Michael Crichton, 'Sphere', 10.99 ],
[ Michael Crichton, 'Jurassic Park', 5.99 ],
[ Michael Crichton, 'The Andromeda Strain', 9.99 ],
[ Michael Crichton, 'Prey', 5.99 ]
]
Wo stecken
var fictionCatalog = [
{
author: 'Michael Crichton',
books: [
{name: 'Sphere', price: 10.99},
{name: 'Jurassic Park', price: 5.99},
{name: 'The Andromeda Strain', price: 9.99},
{name: 'Prey', price: 5.99}
]
}
]
var collection = fictionCatalog.reduce(function(prev, curr) {
return prev.concat(curr.author, curr.books);
}, []);
console.log(collection)
Sie würden eine Art "concatMap" anstelle von "map" benötigen. – Bergi