What's a pragmatic analog to SQL 'JOIN' for tables represented as arrays of Javascript objects? Javascript Array.join
and D3.js 'd3.merge` are not the same concept.
E.g. SELECT * FROM authors LEFT JOIN books ON authors.id = books.author_id
?
First table:
var authors =
[ { id: 1, name: 'adam'},
{ id: 2, name: 'bob'},
{ id: 3, name: 'charlie'}, ...
]
Second table:
var books =
[ { author_id: 1, title: 'Coloring for beginners'},
{ author_id: 1, title: 'Advanced coloring'},
{ author_id: 2, title: '50 Hikes in New England'},
{ author_id: 2, title: '50 Hikes in Illinois'},
{ author_id: 3, title: 'String Theory for Dummies'}, ...
]
The tables are loaded from CSV using D3.js d3.csv()
, so have D3.js already, open to other libs but generally prefer coding directly if not too far out of the way.
I see Native way to merge objects in Javascript which uses RethinkDB, which seems over the top for this, but this is the idea.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…