JSFiddle - React, Tailwind, and code Playground

by dz902

JavaScript

var threads = [{id: 1}, {id: 2}, {id: 3}];
var users = [
	{
  	uid: 0,
  	thread_refs: [
    	{tid: 3, bookmarked: true},
      {tid: 2, bookmarked: true}
    ]
  }
];

var threadMap = [];

threads.forEach(function(thread) {
	threadMap[thread.id] = thread;
});

var bookmarkedThreads = [];

users.forEach(function(user, index) {
	user.thread_refs.forEach(function(ref) {
  	ref.bookmarked ? bookmarkedThreads.push(threadMap[ref.tid]) : null;
  });
});

console.log(bookmarkedThreads);